php - Change the DefaultEntityListenerResolver on Doctrine with ZF2 -


I want to change the principle of success without theory. EntityListener defined trote annotation @ORM \ EntityListeners needs to call the service manager inside.

So I've coded this ListenerResolver to find out whether the listener applies ServiceLocatorAwareInterface:

Class Listener Resellers DefaultEntityListenerResolver {Private $ Service Manager; Public Function __Search (Service Information Interface $ Service Manager) {$ this- & gt; Service manager = $ service manager; } Public Function Resolution ($ className) {$ listener = parent: resolution ($ className); If ($ listener instanceof ServiceLocatorAwareInterface) {$ listener-> SetServiceLocator ($ this-> service provider); } $ Back to listener; } ex> class module {public function at bootstrap (MvcEvent $ e) {$ serviceManager = $ e-> GetTarget () - & gt; GetServiceManager (); $ Reseller = new listerolver ($ service manager); $ ServiceManager- & gt; Mill ('doctrine.entitymanager.orm_default') - & gt; GetConfiguration () - & gt; SetEntityListenerResolver ($ resolver); }}

But I still can not reach the service manager, any suggestions?

The issue is that we do not really need to change EntityListenerResolver, There is a need to register so I registered the listener on the current EntityListenerResolver at bootstrap.

1- Apply ServiceLocatorAwareInterface to each organization listener.

  namespace application \ business \ unit \ listener; Use Zend \ ServiceManager \ ServiceLocatorAwareInterface; Class User Device ServiceLocatorAwareInterface {}  

Register the unit listeners as invokables on 2-module. Php. Public function getServiceConfig () Returns array ('Invokables' = & gt; array (// EntityListeners 'application \ Business \ Entity \ Listener \ User' => Application \ Business \ Entity \ Listener \ User ',),))}}

3 - Register listeners on Bootstrap to Module.php, I have done that list again and listener on invokables Search for namespaces of

  Bootstrap on public functions (MvcEvent $ e) {$ EventManager = $ e- & gt; GetApplication () - & gt; GetEventManager (); $ ModuleRouteListener = New ModuleRouteListener (); $ ModuleRouteListener-> Gave ($ eventManager); // Service Magener INejct $ at serviceManager = $ e- & gt; GetApplication () - & gt; GetServiceManager (); $ EntityManager = $ Service Manager- & gt; Receive ('Principle \ ORM \ Unit Manager'); // Register institution listeners $ config = $ this-> getServiceConfig (); $ INOBIL = $ config ['Incobables']; Foreach ($ invokables $ invokable) {// Confirm listener name location if ((SRPO ($ invoxable, 'application \ business \ unit')! == incorrect) & amp; (Strokes ($ invoxable, ' \ Listener ')! == Incorrect)) {$ entityManager-> GetConfiguration () - & gt; GetEntityListenerResolver () - & gt; Register (get $ Service Manager- & gt; ($ INOKABABLE)); }}}}  

And you are ... now you can freely get $ this-> getServiceLocator () -> (on listeners) hope it helps ..


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -