public function withMiddleware(MiddlewareInterface $middleware)
    {
        if (!($middleware instanceof ServerMiddlewareInterface)) {
            throw new \InvalidArgumentException('ServerMiddlewareInterface request expected.');
        }

        foreach ($this->middlewares as $m) {
            if ($m === $middleware) {
                return $this;
            }
        }
        $this->middlewares[] = $middleware;
        // breaking **** immutability by intention ^^~>
        return $this;
    }
public function withMiddleware(MiddlewareInterface $middleware)
    {
        if (!($middleware instanceof ServerMiddlewareInterface)) {
            throw new \InvalidArgumentException('ServerMiddlewareInterface request expected.');
        }

        foreach ($this->middlewares as $m) {
            if ($m === $middleware) {
                return $this;
            }
        }
        $this->middlewares[] = $middleware;
        // breaking **** immutability by intention ^^~>
        return $this;
    }
public function withMiddleware ( MiddlewareInterface $ middleware ) { if ( ! ( $ middleware instanceof ServerMiddlewareInterface ) ) { throw new \ InvalidArgumentException ( 'ServerMiddlewareInterface request expected.' ) ; } foreach ( $ this -> middlewares as $ m ) { if ( $ m === $ middleware ) { return $ this ; } } $ this -> middlewares [ ] = $ middleware ; // breaking **** immutability by intention ^^~> return $ this ; }
Return an instance with the specified middleware added to the stack.
This method MUST be implemented in such a way as to retain the
immutability of the stack, and MUST return an instance that contains
the specified middleware.

@param MiddlewareInterface $middleware
@return self
Return an instance with the specified middleware added to the stack . This method MUST be implemented in such a way as to retain the immutability of the stack and MUST return an instance that contains the specified middleware .