protected function processPortHeader(ServerRequestInterface $request, UriInterface $uri) { if ($request->hasHeader('X-Forwarded-Port')) { $port = trim(current(explode(',', $request->getHeaderLine('X-Forwarded-Port')))); if (preg_match('/^\\d+\\z/', $port)) { return $uri->withPort((int) $port); } } return $uri; }
/** * Create an UriInterface with the port information from `$server`. It uses `$server['SERVER_PORT']` for this * information. * * @param UriInterface $uri * @param array $server * * @return UriInterface */ private function withServerPort(UriInterface $uri, array $server) : UriInterface { if (isset($server['SERVER_PORT'])) { return $uri->withPort($server['SERVER_PORT']); } return $uri; }