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

How i can get all events=>callbacks? #8

Open
weierophinney opened this issue Dec 31, 2019 · 7 comments
Open

How i can get all events=>callbacks? #8

weierophinney opened this issue Dec 31, 2019 · 7 comments
Labels
Question Further information is requested

Comments

@weierophinney
Copy link
Member

in EventManager v2.* can i get all events names\callbacks for my application


Originally posted by @maxgu at zendframework/zend-eventmanager#22

@weierophinney weierophinney added the Question Further information is requested label Dec 31, 2019
@weierophinney
Copy link
Member Author

Please look at the docs: Removed Functionality


Originally posted by @froschdesign at zendframework/zend-eventmanager#22 (comment)

@weierophinney
Copy link
Member Author

I have dirty solution (in \Zend\EventManager\EventManager):

class EventManager implements EventManagerInterface
{
    // ...
    public static $allEvents = [];
    // ...
    public function attach($event, $callback = null, $priority = 1)
    {
        // ...
        if (empty($this->events[$event])) {
            $this->events[$event] = new PriorityQueue();
            self::$allEvents[$event] = new PriorityQueue();
        }

        // ...

        $this->events[$event]->insert($listener, $priority);
        self::$allEvents[$event]->insert($listener, $priority);
        return $listener;
    }

after this i see all :) but this is unacceptable and very dirty.


Originally posted by @maxgu at zendframework/zend-eventmanager#22 (comment)

@weierophinney
Copy link
Member Author

@froschdesign
no, this not work, because some services have own EventManager:

$this->setEventManager(new EventManager());
// or
$this->events = new EventManager();

in my task i need get all (ALL in whole app) events and handlers.


Originally posted by @maxgu at zendframework/zend-eventmanager#22 (comment)

@weierophinney
Copy link
Member Author

Now i have problem: I have big application with many modules, and when i see in code $this->getEventManager()->trigger($event); i have no idea what will be executed. I investigate this and spend many time with Crtl+F in whole project.

I want solve this faster if i have map: events=>callbacks+priorities, like this:

loadModules
    Zend\Loader\ModuleAutoloader::register 9000
    Zend\ModuleManager\Listener\LocatorRegistrationListener::onLoadModules -1000
    Zend\ModuleManager\Listener\ConfigListener::onloadModulesPre 1000
    Zend\ModuleManager\Listener\ConfigListener::onLoadModules -1000
    Zend\ModuleManager\ModuleManager::onLoadModules 1
loadModule.resolve
    Zend\ModuleManager\Listener\ModuleResolverListener
loadModule
    Zend\ModuleManager\Listener\AutoloaderListener
    Zend\ModuleManager\Listener\ModuleDependencyCheckerListener
    Zend\ModuleManager\Listener\InitTrigger
    Zend\ModuleManager\Listener\OnBootstrapListener
    Zend\ModuleManager\Listener\LocatorRegistrationListener::onLoadModule 1
    Zend\ModuleManager\Listener\ConfigListener::onLoadModule 1
    Zend\ModuleManager\Listener\ServiceListener::onLoadModule 1
mergeConfig
    Zend\ModuleManager\Listener\ConfigListener::onMergeConfig 1000
loadModules.post
    Zend\ModuleManager\Listener\ServiceListener::onLoadModulesPost 1
bootstrap
    Zend\Mvc\View\Http\ViewManager::onBootstrap 10000
route
    Zend\Mvc\RouteListener::onRoute 1
    Zend\Mvc\HttpMethodListener::onRoute 10000
    Zend\Mvc\ModuleRouteListener::onRoute 1
    callback function
    PhlySimplePage\Module::onRoutePost -100
    T4web\Authentication\Service\Checker::check -100
dispatch
    Application\Controller\IndexController::onDispatch 1
sendResponse
    Zend\Mvc\ResponseSender\PhpEnvironmentResponseSender
    Zend\Mvc\ResponseSender\ConsoleResponseSender
    Zend\Mvc\ResponseSender\SimpleStreamResponseSender
    Zend\Mvc\ResponseSender\HttpResponseSender
finish
    Zend\Mvc\SendResponseListener::sendResponse -10000
    callback function
renderer
    Zend\View\Strategy\PhpRendererStrategy::selectRenderer
response
    Zend\View\Strategy\PhpRendererStrategy::injectResponse
dispatch.error
    Zend\Mvc\View\Http\RouteNotFoundStrategy::detectNotFoundError 1
    Zend\Mvc\View\Http\RouteNotFoundStrategy::prepareNotFoundViewModel 1
    Zend\Mvc\View\Http\ExceptionStrategy::prepareExceptionViewModel 1
    Zend\Mvc\View\Http\InjectViewModelListener::injectViewModel -100
render.error
    Zend\Mvc\View\Http\ExceptionStrategy::prepareExceptionViewModel 1
    Zend\Mvc\View\Http\InjectViewModelListener::injectViewModel -100
    Zend\Mvc\View\Http\DefaultRenderingStrategy::render -10000
render
    Zend\Mvc\View\Http\DefaultRenderingStrategy::render -10000

Originally posted by @maxgu at zendframework/zend-eventmanager#22 (comment)

@weierophinney
Copy link
Member Author

@weierophinney
Copy link
Member Author

@froschdesign He's asking about v2, not v3.

@maxgu — The following methods will assist:

  • EventManager::getEvents() returns a list of all events currently registered.
  • EventManager::getListeners($event) returns a list of all CallbackHandlers associated with a given event. Caveat: it only returns those directly attached to the EM instance. You can use $handler->getMetadatum('priority') to get the priority at which the given handler is attached.
  • EventManager::getIdentifiers() will return the list of identifiers the EM instance exposes and will look for shared listeners on.
  • EventManager::getSharedManager() will return the shared event manager instance.
  • SharedEventManager::getEvents() will return a list of all events with shared listeners, across all EM instances; likely, if you're only looking for listeners for a single EM instance, you won't need this.
  • SharedEventManager::getListeners($id, $event) returns a list of CallbackHandlers representing the shared listeners for the given identifier.

Hopefully with the above information, you can stitch something together!


Originally posted by @weierophinney at zendframework/zend-eventmanager#22 (comment)

@weierophinney
Copy link
Member Author

@snapshotpl thnx, but ZfSnapEventDebugger show ONLY triggered on current URI events, it not show (for examlpe):

dispatch.error
    Zend\Mvc\View\Http\RouteNotFoundStrategy::detectNotFoundError 1
    Zend\Mvc\View\Http\RouteNotFoundStrategy::prepareNotFoundViewModel 1
    Zend\Mvc\View\Http\ExceptionStrategy::prepareExceptionViewModel 1
    Zend\Mvc\View\Http\InjectViewModelListener::injectViewModel -100

Originally posted by @maxgu at zendframework/zend-eventmanager#22 (comment)

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

No branches or pull requests

1 participant