public function setUp() { $this->request = new \Zend\Http\PhpEnvironment\Request(); $this->events = new \Zend\EventManager\EventManager(); $this->router = new \Zend\Mvc\Router\Http\TreeRouteStack(); foreach ($this->routeConfig as $name => $route) { $this->router->addRoute($name, $route); } $this->events->attach(new \Zend\Mvc\RouteListener()); $this->events->attach(new \Zend\Mvc\ModuleRouteListener(), -1); }
public function register(PluginHandler\PluginHandlerInterface $plugin) { if ($plugin instanceof PluginHandler\OnInitInterface) { $this->eventManager->attach('init', $plugin, 'onInit'); } if ($plugin instanceof PluginHandler\OnPreDispatchInterface) { $this->eventManager->attach('preDispatch', $plugin, 'onPreDispatch'); } if ($plugin instanceof PluginHandler\OnPostDispatchInterface) { $this->eventManager->attach('postDispatch', $plugin, 'onPostDispatch'); } }
public function register($plugin) { if (method_exists($plugin, 'onInit')) { $this->eventManager->attach('init', $plugin, 'onInit'); } if (method_exists($plugin, 'onPreDispatch')) { $this->eventManager->attach('preDispatch', $plugin, 'onPreDispatch'); } if (method_exists($plugin, 'onPostDispatch')) { $this->eventManager->attach('postDispatch', $plugin, 'onPostDispatch'); } }
<?php require "vendor/autoload.php"; $myEventManager = new \Zend\EventManager\EventManager(); $listener = function ($e) { $p = $e->getParams(); echo "Bonjour {$p['0']}\n"; }; $autre = function ($e) { echo "bye\n"; }; $myEventManager->attach('lundi', $listener, 1); $myEventManager->attach('lundi', $autre, 2); $myEventManager->trigger('lundi', null, array('Nous sommes lundi'));
public function benchmarkZendFrameworkEventManager($b) { $eventManager = new \Zend\EventManager\EventManager(); $eventManager->attach("post-save", function ($assert) { }); for ($i = 0; $i < $b->times(); $i++) { $eventManager->trigger("post-save", $this, ["override"]); } }