示例#1
0
 /**
  * Constructor
  * @param ContainerInterface $container
  */
 public function __construct(ContainerInterface $container)
 {
     if (method_exists($this, 'getConfig')) {
         $container->get('config')->load($this->getConfig());
     }
 }
 /**
  * Call middleware stack
  *
  * @param  ServerRequestInterface $req A request object
  * @param  ResponseInterface      $res A response object
  * @param  ContainerInterface     $container A container object
  *
  * @return ResponseInterface
  */
 public function callMiddlewareStack(ServerRequestInterface $req, ResponseInterface $res, ContainerInterface $container)
 {
     if ($this->middlewareStack === \null) {
         $this->seedMiddlewareStack();
     }
     ksort($this->middlewarePending);
     foreach ($this->middlewarePending as $priority => $middlewares) {
         krsort($middlewares);
         foreach ($middlewares as $k => $middleware) {
             unset($this->middlewarePending[$priority][$k]);
             if (\is_string($middleware) && $container->has($middleware)) {
                 $middleware = $container->get($middleware);
             } elseif (\is_string($middleware) && \class_exists($middleware)) {
                 $middleware = new $middleware();
             }
             if (!\is_callable($middleware)) {
                 continue;
             }
             $this->addMiddleware($middleware);
         }
         unset($this->middlewarePending[$priority]);
     }
     $start = array_pop($this->middlewareStack);
     $this->middlewareLock = \true;
     $res = $start($req, $res);
     $this->middlewareLock = \false;
     return $res;
 }