Beispiel #1
0
 /**
  * Process a request and return a response.
  *
  * @param RequestInterface  $request
  * @param DelegateInterface $delegate
  *
  * @return ResponseInterface
  */
 public function process(RequestInterface $request, DelegateInterface $delegate)
 {
     $response = $delegate->process($request);
     // delegate control to next middleware
     $response->getBody()->write("this is test middleware!");
     return $response;
 }
 /**
  * {@inhertidoc}
  */
 public function process(ServerRequestInterface $request, DelegateInterface $delegate) : ResponseInterface
 {
     $request = $this->generateNewToken($request);
     $response = $delegate->process($request);
     if ($this->isReading($request) || $this->tokensMatch($request)) {
         $response = $this->addCookieToResponse($response);
     }
     return $response;
 }
 /**
  * {@inhertidoc}
  */
 public function process(ServerRequestInterface $request, DelegateInterface $delegate) : ResponseInterface
 {
     // If a session driver has been configured, we will need to start the session
     // so that the data is ready.
     if ($this->isSessionConfigured()) {
         // Note that the Narrowspark sessions do not make use of PHP
         // "native" sessions in any way since they are crappy.
         $session = $this->startSession($request);
     }
     $response = $delegate->process($request);
     // Again, if the session has been configured we will need to close out the session
     // so that the attributes may be persisted to some storage medium. We will also
     // add the session identifier cookie to the application response headers now.
     if ($this->isSessionConfigured()) {
         $this->collectGarbage($session);
         $response = $this->addCookieToResponse($response, $session);
         $session->save();
     }
     return $response;
 }
 /**
  * Dispatch the next delegate.
  *
  * For DelegateInterface implementations, calls the process method with
  * only the request instance.
  *
  * For callables, calls with request, response, and error.
  *
  * @param callable|DelegateInterface $nextDelegate
  * @param RequestInterface $request
  * @param ResponseInterface|null $response
  * @param mixed $err
  * @return ResponseInterface
  */
 private function dispatchNextDelegate($nextDelegate, RequestInterface $request, ResponseInterface $response = null, $err = null)
 {
     if ($nextDelegate instanceof DelegateInterface && (!$nextDelegate instanceof Next || $err === null)) {
         return $nextDelegate->process($request);
     }
     $response = $response ?: $this->getResponsePrototype();
     $this->validateServerRequest($request);
     return $nextDelegate($request, $response, $err);
 }
 /**
  * {@inheritdoc}
  */
 public function process(RequestInterface $request, DelegateInterface $delegate)
 {
     return $this->encrypt($delegate->process($this->decrypt($request)));
 }
 public function process(ServerRequestInterface $request, DelegateInterface $delegate)
 {
     $response = $delegate->process($request);
     $response = $response->withBody((new StreamFactory())->createStream($response->getBody() . '-' . $request->getAttribute('foo-middleware') . '-controller-closure'));
     return $response;
 }
Beispiel #7
0
 public function process(ServerRequestInterface $request, DelegateInterface $delegate)
 {
     $response = $delegate->process($request);
     return $response->withBody((new StreamFactory())->createStream('caught'));
 }
 /**
  * Middleware to handle errors and exceptions in layers it wraps.
  *
  * Adds an error handler that will convert PHP errors to ErrorException
  * instances.
  *
  * Internally, wraps the call to $next() in a try/catch block, catching
  * all PHP Throwables (PHP 7) and Exceptions (PHP 5.6 and earlier).
  *
  * When an exception is caught, an appropriate error response is created
  * and returned instead; otherwise, the response returned by $next is
  * used.
  *
  * @param ServerRequestInterface $request
  * @param DelegateInterface $delegate
  * @return ResponseInterface
  */
 public function process(ServerRequestInterface $request, DelegateInterface $delegate)
 {
     set_error_handler($this->createErrorHandler());
     try {
         $response = $delegate->process($request);
         if (!$response instanceof ResponseInterface) {
             throw new MissingResponseException('Application did not return a response');
         }
     } catch (Throwable $e) {
         $response = $this->handleThrowable($e, $request);
     } catch (Exception $e) {
         $response = $this->handleThrowable($e, $request);
     }
     restore_error_handler();
     return $response;
 }
Beispiel #9
0
 public function process(ServerRequestInterface $request, DelegateInterface $delegate)
 {
     $request = $request->withAttribute('foo-middleware', 'foo-middleware');
     $response = $delegate->process($request);
     return $response;
 }