RKA\Middleware\IpAddress::determineClientIpAddress PHP Метод

determineClientIpAddress() защищенный Метод

Find out the client's IP address from the headers available to us
protected determineClientIpAddress ( Psr\Http\Message\ServerRequestInterface $request ) : string
$request Psr\Http\Message\ServerRequestInterface PSR-7 Request
Результат string
    protected function determineClientIpAddress($request)
    {
        $ipAddress = null;
        $serverParams = $request->getServerParams();
        if (isset($serverParams['REMOTE_ADDR']) && $this->isValidIpAddress($serverParams['REMOTE_ADDR'])) {
            $ipAddress = $serverParams['REMOTE_ADDR'];
        }
        $checkProxyHeaders = $this->checkProxyHeaders;
        if ($checkProxyHeaders && !empty($this->trustedProxies)) {
            if (!in_array($ipAddress, $this->trustedProxies)) {
                $checkProxyHeaders = false;
            }
        }
        if ($checkProxyHeaders) {
            foreach ($this->headersToInspect as $header) {
                if ($request->hasHeader($header)) {
                    $ip = $this->getFirstIpAddressFromHeader($request, $header);
                    if ($this->isValidIpAddress($ip)) {
                        $ipAddress = $ip;
                        break;
                    }
                }
            }
        }
        return $ipAddress;
    }