Source of file RouteListener.php
Size: 2,289 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Mvc/RouteListener.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Mvc; use Zend\EventManager\EventManagerInterface; use Zend\EventManager\ListenerAggregateInterface; class RouteListener implements ListenerAggregateInterface { /** * @var \Zend\Stdlib\CallbackHandler[] */ protected $listeners = array(); /** * Attach to an event manager * * @param EventManagerInterface $events * @return void */ public function attach(EventManagerInterface $events) { $this->listeners[] = $events->attach(MvcEvent::EVENT_ROUTE, array($this, 'onRoute')); } /** * Detach all our listeners from the event manager * * @param EventManagerInterface $events * @return void */ public function detach(EventManagerInterface $events) { foreach ($this->listeners as $index => $listener) { if ($events->detach($listener)) { unset($this->listeners[$index]); } } } /** * Listen to the "route" event and attempt to route the request * * If no matches are returned, triggers "dispatch.error" in order to * create a 404 response. * * Seeds the event with the route match on completion. * * @param MvcEvent $e * @return null|Router\RouteMatch */ public function onRoute($e) { $target = $e->getTarget(); $request = $e->getRequest(); $router = $e->getRouter(); $routeMatch = $router->match($request); if (!$routeMatch instanceof Router\RouteMatch) { $e->setError(Application::ERROR_ROUTER_NO_MATCH); $results = $target->getEventManager()->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $e); if (count($results)) { $return = $results->last(); } else { $return = $e->getParams(); } return $return; } $e->setRouteMatch($routeMatch); return $routeMatch; } } |