/** * adds the session to the request arguments * sets userAgent and clientIp * * @param ServerRequestInterface $request * @param ResponseInterface $response * @param callable $next * @return ResponseInterface */ public function init(ServerRequestInterface $request, ResponseInterface $response, callable $next) { $server = $request->getServerParams(); $this->userAgent = $server["HTTP_USER_AGENT"] ?? "-"; $ip = $server["HTTP_X_FORWARDED_FOR"] ?? $server["REMOTE_ADDR"]; if (strpos($ip, ",") !== false) { $ip = substr($ip, 0, strpos($ip, ",")); } $this->clientIp = isset($ip[0]) ? $ip : null; return $next($request->withAttribute(self::REQUEST_ATTRIBUTE, $this), $response); }
/** * adds the database to the request attributes * * @param ServerRequestInterface $request * @param ResponseInterface $response * @param callable $next * @return ResponseInterface */ public function init(ServerRequestInterface $request, ResponseInterface $response, callable $next) { return $next($request->withAttribute(self::REQUEST_ATTRIBUTE, $this), $response); }