akrabat / ip-address-middleware

PSR-7 Middleware that determines the client IP address and stores it as an ServerRequest attribute
Other
167 stars 37 forks source link

second Parameter of __invoke should be RequestHandlerInterface instance #41

Open manhhoangfnq opened 4 months ago

manhhoangfnq commented 4 months ago
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

akrabat commented 1 month ago

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