Exemple #1
0
 private function dispatch($handler, ServerRequestInterface $request) : ResponseInterface
 {
     $next = function () {
         throw new HttpNotFound();
     };
     return $this->invoker->invoke($handler, $request, $next);
 }
Exemple #2
0
 /**
  * Handle the given HTTP request and returns an HTTP response.
  *
  * Unlike run() this method doesn't write anything to the output. Use it in tests.
  *
  * @see run() for a more high-level method.
  */
 public function handle(ServerRequestInterface $request) : ResponseInterface
 {
     // Leaf middleware: resource not found
     $leaf = function () {
         throw new HttpNotFound();
     };
     return $this->invoker->invoke($this->middleware, $request, $leaf);
 }
Exemple #3
0
 public function __invoke(ServerRequestInterface $request, callable $next) : ResponseInterface
 {
     foreach (array_reverse($this->middlewares) as $middleware) {
         $next = function (ServerRequestInterface $request) use($middleware, $next) {
             return $this->invoker->invoke($middleware, $request, $next);
         };
     }
     // Invoke the root middleware
     return $next($request);
 }
Exemple #4
0
 public function __invoke(ServerRequestInterface $request, callable $next) : ResponseInterface
 {
     $path = $request->getUri()->getPath();
     foreach ($this->routes as $pathPrefix => $middleware) {
         if (strpos($path, $pathPrefix) === 0) {
             return $this->invoker->invoke($middleware, $request, $next);
         }
     }
     return $next($request);
 }