Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ProxyManager? #5

Open
danmichaelo opened this issue Apr 16, 2017 · 1 comment
Open

Use ProxyManager? #5

danmichaelo opened this issue Apr 16, 2017 · 1 comment

Comments

@danmichaelo
Copy link
Member

We're using lazy loading e.g. in in Bib::getRecord. Perhaps the implementation could benefit from using ProxyManager.

@danmichaelo
Copy link
Member Author

danmichaelo commented Apr 17, 2017

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;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant