Пример #1
0
 /**
  * If route has middlewares add it to the middleware dispatcher.
  *
  * @param array $middlewares
  */
 private function addMiddlewares(array $middlewares)
 {
     if (count($middlewares['with']) !== 0) {
         foreach ($middlewares['with'] as $middleware) {
             $this->middlewareDispatcher->withMiddleware($middleware);
         }
     }
     if (count($middlewares['without']) !== 0) {
         foreach ($middlewares['without'] as $middleware) {
             $this->middlewareDispatcher->withoutMiddleware($middleware);
         }
     }
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function dispatch(ServerRequestInterface $request, ResponseInterface $response) : ResponseInterface
 {
     $middlewareDispatcher = new MiddlewareDispatcher($response);
     if (isset($this->middlewares['with'])) {
         foreach ($this->middlewares['with'] as $middleware) {
             $middlewareDispatcher->withMiddleware($middleware);
         }
     }
     if (isset($this->middlewares['without'])) {
         foreach ($this->middlewares['without'] as $middleware) {
             $middlewareDispatcher->withoutMiddleware($middleware);
         }
     }
     $dispatcher = new Dispatcher($this->path, $this->routes, $middlewareDispatcher, $this->refreshCache, $this->globalParameterConditions);
     if ($this->events !== null) {
         $dispatcher->setEventsDispatcher($this->events);
         $this->events = $dispatcher->getEventsDispatcher();
     }
     $middlewareDispatcher = $dispatcher->handle($request);
     $this->current = $dispatcher->getCurrentRoute();
     return $middlewareDispatcher->process($request);
 }