Ejemplo n.º 1
0
 /**
  * @param RouteEvent $event
  */
 public function onRoute(RouteEvent $event)
 {
     /**
      * @var RouteInterface $route
      * @var string         $html
      */
     $route = $event->getRoute();
     $html = '';
     // Html
     $html .= sprintf('<h1>Bye %s (%s)</h1>', $route->getParam('name'), $route->getParam('id'));
     $data = $this->getRequest()->getData();
     foreach ($data as $key => $value) {
         $html .= sprintf('<b>%s</b> => %s<br />', $key, $value);
     }
     // Content
     $content = new Html();
     $content->setHtml($html);
     // Response
     $this->getResponse()->setContent($content);
 }
Ejemplo n.º 2
0
 /**
  * @param RouteEvent $event
  */
 public function onRoute(RouteEvent $event)
 {
     $content = new Json();
     $content->setJson(['message' => sprintf($this->getMessage(), $event->getRoute()->getParam('name'))]);
     $this->getResponse()->setContent($content);
 }
Ejemplo n.º 3
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;
 }