ip-address-middleware
ip-address-middleware copied to clipboard
second Parameter of __invoke should be RequestHandlerInterface instance
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
How are you calling the middleware? If you are using PSR-15, then you should be using process()
, not __invoke()
.