ip-address-middleware icon indicating copy to clipboard operation
ip-address-middleware copied to clipboard

second Parameter of __invoke should be RequestHandlerInterface instance

Open manhhoangfnq opened this issue 10 months ago • 1 comments

public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)`
    {
        if (!$next) {
            return $response;
        }

        $ipAddress = $this->determineClientIpAddress($request);
        $request = $request->withAttribute($this->attributeName, $ipAddress);

        return $response = $next($request, $response);
  }

I got the error exception.

[FATAL] RKA\Middleware\IpAddress::__invoke(): Argument # 2 ($response) must be of type Psr\Http\Message\ResponseInterface, Psr\Http\Server\RequestHandlerInterface@anonymous given, called in /vendor/slim/slim/Slim/MiddlewareDispatcher.php on line 168

manhhoangfnq avatar Apr 22 '24 10:04 manhhoangfnq

How are you calling the middleware? If you are using PSR-15, then you should be using process(), not __invoke().

akrabat avatar Jul 15 '24 17:07 akrabat