public function process(RequestInterface $request)
    {
        if ($this->processingStack !== null) {
            throw new \RuntimeException('Middleware stack is already processing.');
        }
        if (!count($this->middlewares)) {
            throw new \RuntimeException('Middleware stack is empty.');
        }
        if (!($request instanceof ServerRequestInterface)) {
            throw new \InvalidArgumentException('ServerRequest request expected.');
        }
        $this->processingStack = array_reverse($this->middlewares);
        /** @var ServerMiddlewareInterface $middleware */
        $middleware = array_shift($this->processingStack);
        return $middleware->process($request, $this);
    }
public function process(RequestInterface $request)
    {
        if ($this->processingStack !== null) {
            throw new \RuntimeException('Middleware stack is already processing.');
        }
        if (!count($this->middlewares)) {
            throw new \RuntimeException('Middleware stack is empty.');
        }
        if (!($request instanceof ServerRequestInterface)) {
            throw new \InvalidArgumentException('ServerRequest request expected.');
        }
        $this->processingStack = array_reverse($this->middlewares);
        /** @var ServerMiddlewareInterface $middleware */
        $middleware = array_shift($this->processingStack);
        return $middleware->process($request, $this);
    }
public function process ( RequestInterface $ request ) { if ( $ this -> processingStack !== null ) { throw new \ RuntimeException ( 'Middleware stack is already processing.' ) ; } if ( ! count ( $ this -> middlewares ) ) { throw new \ RuntimeException ( 'Middleware stack is empty.' ) ; } if ( ! ( $ request instanceof ServerRequestInterface ) ) { throw new \ InvalidArgumentException ( 'ServerRequest request expected.' ) ; } $ this -> processingStack = array_reverse ( $ this -> middlewares ) ; /** @var ServerMiddlewareInterface $middleware */ $ middleware = array_shift ( $ this -> processingStack ) ; return $ middleware -> process ( $ request , $ this ) ; }
Process the request through middleware and return the response.
This method MUST be implemented in such a way as to allow the same
stack to be reused for processing multiple requests in sequence.

@param RequestInterface $request
@return ResponseInterface
Process the request through middleware and return the response . This method MUST be implemented in such a way as to allow the same stack to be reused for processing multiple requests in sequence .