Use ProxyManager?
danmichaelo opened this issue · 1 comments
danmichaelo commented
We're using lazy loading e.g. in in Bib::getRecord
. Perhaps the implementation could benefit from using ProxyManager.
danmichaelo commented
Seems like Ghost Object Proxies could be used. It's possible to exclude some properties from triggering the loading. E.g. in Bibs
:
public function get()
{
$args = func_get_args();
$id = $args[0];
$factory = new LazyLoadingGhostFactory();
$initializer = function (
GhostObjectInterface $ghostObject,
string $method,
array $parameters,
& $initializer,
array $properties
) {
$initializer = null; // disable initialization
// load data and modify the object here (note: the constructor has not yet been called)
// $properties["\0*\0mms_id"] = $id; // Inherited from proxy object?
$ghostObject->load();
return true; // confirm that initialization occurred correctly
};
$proxyOptions = [
'skippedProperties' => [
"\0*\0mms_id",
"\0*\0client",
"\0*\0_holdings", // Will this work?
],
];
$instance = $factory->createProxy(\Scriptotek\Bibs\Bib::class, $initializer, $proxyOptions);
$instance->mms_id = $id;
return $instance;
}