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

The mvc event listener invalid for namespace if it's multi segment namespaces #14

Closed
weierophinney opened this issue Dec 31, 2019 · 3 comments

Comments

@weierophinney
Copy link
Member

There is a question for me.
On a module, Like the path: module/Application, module/Admin, etc...
Most of time. the module namespace is use: Application\, Admin\, and now I want make a module is common module for other project. So I rename the namespace to: Brand\Admin\ replace the old Admin\ like this.
And then. the question is happened. I tracking all the script flow. The event manager just register the auto namespace first segment for the event identifier. Like the Brand\Admin\ registered in the identifiers is Brand
So I register listener on a module's onBootstrap() can not been called.

Code to reproduce the issue

namespace Brand\Admin
class Module {
//.... other code
public function onBootstrap(MvcEvent $event) {

        $sharedEventManager = $event->getApplication()->getEventManager()->getSharedManager();
        $sharedEventManager->attach(__NAMESPACE__, MvcEvent::EVENT_DISPATCH, function ($e) {
            echo '<h1>Hello, Baby!</h1>';
        }, 9999);
        // The will be ok. the eventmanager auto register identifier AbstractActionController
        //$sharedEventManager->attach(Zend\Mvc\Controller\AbstractActionController::class, MvcEvent::EVENT_DISPATCH, function ($e) {
            //echo '<h1>Hello, Baby!</h1>';
        //}, 9999);
        // Or not use shared event manager, use eventManger is OK.
    }
}

Expected results

the never output hello, baby.

Actual results

The listener never been called.


Originally posted by @leogitpro at zendframework/zend-mvc#274

@weierophinney
Copy link
Member Author

I debug the EventManager->triggerListeners() method.
The class identifiers attribute include the followed ids.

Array (
  [0] => Zend\Mvc\Controller\AbstractController
  [1] => Application\Controller\IndexController
  [2] => Application // Notice there, if visit admin module. There will been: Brand, not expected: Brand\Admin
  [3] => Zend\Mvc\InjectApplicationEventInterface
  [4] => Zend\EventManager\EventsCapableInterface
  [5] => Zend\EventManager\EventManagerAwareInterface
  [6] => Zend\Stdlib\DispatchableInterface
  [7] => Zend\Mvc\Controller\AbstractActionController
)
Who can tell me the module namespace where, when added to the event manager identifiers?
Thanks so much.


Originally posted by @leogitpro at zendframework/zend-mvc#274 (comment)

@weierophinney
Copy link
Member Author

#282 Should fix this


Originally posted by @Xerkus at zendframework/zend-mvc#274 (comment)

@samsonasik
Copy link
Member

should already fixed in zendframework/zend-mvc#282 . Please re-create issue if the problem persist.

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