/** * ServerRequest constructor. * * @param array $get * @param array $post * @param array $files * @param array $cookie * @param array $server * @param SessionHandler|null $sessionHandler */ public function __construct(array $get = [], array $post = [], array $files = [], array $cookie = [], array $server = [], SessionHandler $sessionHandler = null) { $this->query = new Bag($get); $this->body = new Bag($post); $this->server = new ServerBag($server); $this->cookie = new CookieBag($cookie); $this->file = new FileBag($files); $headers = []; array_walk($server, function ($value, $key) use(&$headers) { if (0 === strpos($key, 'HTTP_')) { $headers[$key] = $value; } }); parent::__construct(sprintf('%s://%s', $this->server->getScheme(), $this->server->getHost() . $this->server->getBaseUrl() . $this->server->getPathInfo()), $headers, 'php://input'); $this->withMethod($this->server->getMethod()); unset($headers); try { $sessionKey = $this->getHeaderLine(Session::SESSION_KEY); } catch (InvalidArgumentException $e) { $sessionKey = null; } $this->session = Session::start($sessionKey, $sessionHandler); $this->withHeader(Session::SESSION_KEY, $this->session->getSessionId()); $this->withCookieParams([Session::SESSION_KEY => $this->session->getSessionId()]); }
public function testUrlInfo() { $serverBag = new ServerBag($this->_server); $this->assertEquals('localhost', $serverBag->getHost()); $this->assertFalse($serverBag->isSecure()); $this->assertEquals($serverBag->getScheme(), 'http'); $this->assertEquals($serverBag->getPort(), 80); }