ServerBag.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. /**
  20. * Gets the HTTP headers.
  21. *
  22. * @return string
  23. */
  24. public function getHeaders()
  25. {
  26. $headers = array();
  27. foreach ($this->parameters as $key => $value) {
  28. if (0 === strpos($key, 'HTTP_')) {
  29. $headers[substr($key, 5)] = $value;
  30. }
  31. // CONTENT_* are not prefixed with HTTP_
  32. elseif (in_array($key, array('CONTENT_LENGTH', 'CONTENT_MD5', 'CONTENT_TYPE'))) {
  33. $headers[$key] = $this->parameters[$key];
  34. }
  35. }
  36. // PHP_AUTH_USER/PHP_AUTH_PW
  37. if (isset($this->parameters['PHP_AUTH_USER'])) {
  38. $pass = isset($this->parameters['PHP_AUTH_PW']) ? $this->parameters['PHP_AUTH_PW'] : '';
  39. $headers['AUTHORIZATION'] = 'Basic '.base64_encode($this->parameters['PHP_AUTH_USER'].':'.$pass);
  40. }
  41. return $headers;
  42. }
  43. }