/** * Method to test getValue(). * * @return void * * @covers \Windwalker\Http\Helper\HeaderHelper::getValue */ public function testGetValue() { $headers = array('x-foo' => 'baz', 'X-Flower' => array('sakura', 'olive')); $this->assertEquals('baz', HeaderHelper::getValue($headers, 'x-foo')); $this->assertEquals('sakura, olive', HeaderHelper::getValue($headers, 'x-flower')); $this->assertEquals('default', HeaderHelper::getValue($headers, 'x-car', 'default')); }
/** * Marshal the host and port from HTTP headers and/or the PHP environment * * @param string $host The uri host. * @param string $port The request port. * @param array $server The $_SERVER superglobal. * @param array $headers The headers variable from server. */ public static function getHostAndPortFromHeaders(&$host, &$port, array $server, array $headers) { if (HeaderHelper::getValue($headers, 'host', false)) { static::getHostAndPortFromHeader($host, $port, HeaderHelper::getValue($headers, 'host')); return; } if (!isset($server['SERVER_NAME'])) { return; } $host = $server['SERVER_NAME']; if (isset($server['SERVER_PORT'])) { $port = (int) $server['SERVER_PORT']; } if (!isset($server['SERVER_ADDR']) || !preg_match('/^\\[[0-9a-fA-F\\:]+\\]$/', $host)) { return; } // Handle Ipv6 $host = '[' . $server['SERVER_ADDR'] . ']'; $port = $port ?: 80; if ($port . ']' === substr($host, strrpos($host, ':') + 1)) { // The last digit of the IPv6-Address has been taken as port // Unset the port so the default port can be used $port = null; } }