/** * @test */ public function createFromServerSimulatesAuthorizationHeaderIfPHPAuthVariablesArePresent() { $server = array('PHP_AUTH_USER' => 'robert', 'PHP_AUTH_PW' => 'mysecretpassword, containing a : colon ;-)'); $headers = Headers::createFromServer($server); $expectedValue = 'Basic ' . base64_encode('robert:mysecretpassword, containing a : colon ;-)'); $this->assertEquals($expectedValue, $headers->get('Authorization')); $this->assertFalse($headers->has('User')); }
/** * Constructs a new Request object based on the given environment data. * * @param array $get Data similar to that which is typically provided by $_GET * @param array $post Data similar to that which is typically provided by $_POST * @param array $files Data similar to that which is typically provided by $_FILES * @param array $server Data similar to that which is typically provided by $_SERVER * @see create() * @see createFromEnvironment() * @api */ public function __construct(array $get, array $post, array $files, array $server) { $this->headers = Headers::createFromServer($server); $this->setMethod(isset($server['REQUEST_METHOD']) ? $server['REQUEST_METHOD'] : 'GET'); $protocol = isset($server['SSL_SESSION_ID']) || isset($server['HTTPS']) && ($server['HTTPS'] === 'on' || strcmp($server['HTTPS'], '1') === 0) ? 'https' : 'http'; $this->uri = new Uri($protocol . '://' . (isset($server['HTTP_HOST']) ? $server['HTTP_HOST'] : 'localhost') . str_replace('/index.php', '', isset($server['REQUEST_URI']) ? $server['REQUEST_URI'] : '/')); $this->server = $server; $this->arguments = $this->buildUnifiedArguments($get, $post, $files); }