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

Add ability to register event subscriber #65

Open
wants to merge 2 commits into
base: master
from

Conversation

@Baachi
Copy link

Baachi commented Nov 4, 2019

Hey Guys,

I created a compiler pass, which adds the ability to register event subscribers/listeners via service tags.

@Baachi Baachi force-pushed the Baachi:feature/event-listener branch from 6abd86e to 1bf6a1f Nov 4, 2019
@Baachi Baachi force-pushed the Baachi:feature/event-listener branch from 1bf6a1f to cb82245 Nov 4, 2019
@xavismeh

This comment has been minimized.

Copy link
Collaborator

xavismeh commented Nov 4, 2019

Hello @Baachi,
Thanks for this (very first!) contribution. We did not implement this before because the original graphaware lib already have this feature and this is, by the way, what we use to log queries (see https://github.com/neo4j-contrib/neo4j-symfony/blob/master/EventSubscriber/LoggerSubscriber.php).
Do you have a use case where this would not be good enough?

@Baachi

This comment has been minimized.

Copy link
Author

Baachi commented Nov 4, 2019

Hey @xavismeh,

sure if you want to use the OGM you have to use the EventManager. Especially we use the preFlush/postFlush/onFlush events from OGM, which is only supported be EventManager.

https://github.com/graphaware/neo4j-php-ogm/blob/master/src/UnitOfWork.php#L200-L202

@Baachi Baachi force-pushed the Baachi:feature/event-listener branch from 4fee72c to 710d966 Nov 4, 2019
@xavismeh

This comment has been minimized.

Copy link
Collaborator

xavismeh commented Nov 4, 2019

If I understand correctly your need, you might want to do something like this (not tested):

<?php

use Doctrine\Common\EventSubscriber;
use GraphAware\Neo4j\OGM\Event\PreFlushEventArgs;

class myCustomSubscriber implements EventSubscriber
{
    public function getSubscribedEvents()
    {
        return ['onPreFlush'];
    }

    public function onPreFlush(PreFlushEventArgs $event)
    {
        // ... my custom logic
    }
}
@Baachi

This comment has been minimized.

Copy link
Author

Baachi commented Nov 4, 2019

Exactly :)

@Baachi

This comment has been minimized.

Copy link
Author

Baachi commented Nov 14, 2019

@xavismeh Ping :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.