Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

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

Open
maxgu opened this issue Feb 18, 2016 · 8 comments
Open

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

maxgu opened this issue Feb 18, 2016 · 8 comments
Labels

Comments

@maxgu
Copy link

maxgu commented Feb 18, 2016

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

@froschdesign
Copy link
Member

Please look at the docs: Removed Functionality

@maxgu
Copy link
Author

maxgu commented Feb 18, 2016

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.

@maxgu
Copy link
Author

maxgu commented Feb 18, 2016

@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.

@maxgu
Copy link
Author

maxgu commented Feb 18, 2016

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

@snapshotpl
Copy link
Contributor

@weierophinney
Copy link
Member

@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!

@maxgu
Copy link
Author

maxgu commented Feb 18, 2016

@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

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-eventmanager; a new issue has been opened at laminas/laminas-eventmanager#8.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants