ServerBag.php 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpFoundation;
  11. /**
  12. * ServerBag is a container for HTTP headers from the $_SERVER variable.
  13. *
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. * @author Bulat Shakirzyanov <mallluhuct@gmail.com>
  16. */
  17. class ServerBag extends ParameterBag
  18. {
  19. public function getHeaders()
  20. {
  21. $headers = array();
  22. foreach ($this->parameters as $key => $value) {
  23. if (0 === strpos($key, 'HTTP_')) {
  24. $headers[substr($key, 5)] = $value;
  25. }
  26. // CONTENT_* are not prefixed with HTTP_
  27. elseif (in_array($key, array('CONTENT_LENGTH', 'CONTENT_MD5', 'CONTENT_TYPE'))) {
  28. $headers[$key] = $value;
  29. }
  30. }
  31. // PHP_AUTH_USER/PHP_AUTH_PW
  32. if (isset($this->parameters['PHP_AUTH_USER'])) {
  33. $pass = isset($this->parameters['PHP_AUTH_PW']) ? $this->parameters['PHP_AUTH_PW'] : '';
  34. $headers['AUTHORIZATION'] = 'Basic '.base64_encode($this->parameters['PHP_AUTH_USER'].':'.$pass);
  35. }
  36. return $headers;
  37. }
  38. }