2011-01-22 17:34:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-01-22 17:34:18 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Component\HttpFoundation;
|
|
|
|
|
|
|
|
/**
|
2011-07-28 10:27:56 +01:00
|
|
|
* ServerBag is a container for HTTP headers from the $_SERVER variable.
|
2011-01-22 17:34:18 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2011-01-22 17:34:18 +00:00
|
|
|
* @author Bulat Shakirzyanov <mallluhuct@gmail.com>
|
|
|
|
*/
|
|
|
|
class ServerBag extends ParameterBag
|
|
|
|
{
|
2011-11-02 15:42:51 +00:00
|
|
|
/**
|
2011-11-04 09:19:48 +00:00
|
|
|
* Gets the HTTP headers.
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
|
|
|
* @return string
|
2011-11-02 15:42:51 +00:00
|
|
|
*/
|
2011-01-22 17:34:18 +00:00
|
|
|
public function getHeaders()
|
|
|
|
{
|
|
|
|
$headers = array();
|
|
|
|
foreach ($this->parameters as $key => $value) {
|
2012-01-11 19:20:58 +00:00
|
|
|
if (0 === strpos($key, 'HTTP_')) {
|
2011-02-04 11:20:47 +00:00
|
|
|
$headers[substr($key, 5)] = $value;
|
2011-01-22 17:34:18 +00:00
|
|
|
}
|
2011-08-24 19:56:02 +01:00
|
|
|
// CONTENT_* are not prefixed with HTTP_
|
|
|
|
elseif (in_array($key, array('CONTENT_LENGTH', 'CONTENT_MD5', 'CONTENT_TYPE'))) {
|
2011-06-08 10:04:41 +01:00
|
|
|
$headers[$key] = $this->parameters[$key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-13 13:12:03 +01:00
|
|
|
// PHP_AUTH_USER/PHP_AUTH_PW
|
|
|
|
if (isset($this->parameters['PHP_AUTH_USER'])) {
|
2011-07-26 08:32:45 +01:00
|
|
|
$pass = isset($this->parameters['PHP_AUTH_PW']) ? $this->parameters['PHP_AUTH_PW'] : '';
|
|
|
|
$headers['AUTHORIZATION'] = 'Basic '.base64_encode($this->parameters['PHP_AUTH_USER'].':'.$pass);
|
2011-07-13 13:12:03 +01:00
|
|
|
}
|
|
|
|
|
2011-01-22 17:34:18 +00:00
|
|
|
return $headers;
|
|
|
|
}
|
|
|
|
}
|