Ejemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function dispatch(RequestInterface $request)
 {
     /**
      * @var null|RouteInterface      $routeMatch
      * @var RoutingStrategyInterface $routingStrategy
      * @var array                    $routes
      * @var int                      $i
      */
     $routeMatch = null;
     $routingStrategy = $this->getRoutingStrategy();
     $routes = array_keys($this->routes);
     $i = 0;
     // While no route match found and more routes to test
     while ($routeMatch instanceof RouteInterface === false && isset($routes[$i])) {
         /**
          * @var RouteInterface $route
          */
         $route = $this->getRoute($routes[$i]);
         // Match the route and the request
         if ($routingStrategy->match($route, $request)) {
             // Match found
             $routeMatch = $route;
         }
         $i++;
     }
     // Create "route found" event
     $event = new RouteEvent();
     // Route found
     if ($routeMatch instanceof RouteInterface) {
         $event->setName(RouteEvent::FOUND)->setRoute($routeMatch);
         $event->setName($routeMatch->getName())->setRoute($routeMatch);
         // Route not found
     } else {
         $event->setName(RouteEvent::NOT_FOUND);
     }
     // Trigger event
     $this->getEventManager()->trigger($event);
     return $this;
 }