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

GetSubscribedEvents on partially initialized instance. #63

Closed
hrach opened this issue Dec 29, 2014 · 8 comments
Closed

GetSubscribedEvents on partially initialized instance. #63

hrach opened this issue Dec 29, 2014 · 8 comments

Comments

@hrach
Copy link

hrach commented Dec 29, 2014

getting the subscribed events is quite hacky, for example injections are not injected... so, it is impossible to do any logic in there. I see no added value in this, make it static, or create the instance properly, what do you think?

@hrach hrach changed the title GetSubscibedEvents GetSubscribedEvents on partially initialized instance. Dec 29, 2014
@fprochazka
Copy link
Member

It's meant to be static, but I'm not sure we can do that because of Subscriber interface.

I don't see how the instance can be created properly in compile time. The listener might depend on classes that require shitload of dependencies. I would have to fake-compile the entire container to be able to properly create the listener instances.

Any ideas?

@fprochazka
Copy link
Member

I suppose we can create the listener "properly", when the constructor has no dependencies or when it depends only on parameters, not services. Any thoughts?

@hrach
Copy link
Author

hrach commented Jan 1, 2015

Well, let me clear the need, then it may be more obvious. I have a neo4j services, which store some metadata (and updated them through events). I have it also on my local machine, but not every developer should be forced to have it, since it's just small part of the app. So I would like to add listener somehow conditionaly. This was the first idea (the easiest): to let me inject my ParameterProvider, when I have option for it.

What is the proper solution?

@fprochazka
Copy link
Member

You might have a listener that is invoked on connection to database or application init, that adds another listener if needed. You don't have to specify all events in the getSubscribedEvents, you may add them manually.

Might something like this help?

class SomeListener implements Subsriber
{
    public function __construct(EventManager $evm)
    {
        // ...
    }

    public function getSubscribedEvents()
    {
        return ['Neo4js::onConnect'];
    }

    public function onConnect(...)
    {
        // ...
        $this->evm->addEventListener('Neo4js::onMetadataUpdate', [$this, 'onMetadataUpdate']);
    }

    public function onMetadataUpdate(..)
    {
        // ...
    }

Doctrine uses similar mechanism to add listener for onClear in it's hydrator. Because it doesn't have the lazy listeners natively and therefore it adds it only when it's needed.

But I'm not sure I've understood you properly. Možná to bude snadnější česky?

@hrach
Copy link
Author

hrach commented Jan 1, 2015

You understood it correcty. The problem is, the connection is needed only when the event occurs.

@hrach
Copy link
Author

hrach commented Jan 23, 2015

Well, I solved this by own extension. So, I don't need any features for doing this, but I would force the getSbscribedEvents to be static.

@fprochazka
Copy link
Member

I don't consider this a problem. If you provide better solution that will not break BC, I shall consider it.

@hrach
Copy link
Author

hrach commented Mar 7, 2015

What? Why should I provide solution for something ,which isn't a problem :P

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

2 participants