PageRenderTime 51ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/symfony/src/Symfony/Component/BrowserKit/Response.php

https://github.com/casoetan/ServerGroveLiveChat
PHP | 104 lines | 47 code | 11 blank | 46 comment | 4 complexity | 122c629b277388e5b49f8a758e5d969c MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, ISC, BSD-3-Clause
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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\BrowserKit;
  11. /**
  12. * Response object.
  13. *
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. */
  16. class Response
  17. {
  18. protected $content;
  19. protected $status;
  20. protected $headers;
  21. /**
  22. * Constructor.
  23. *
  24. * The headers array is a set of key/value pairs. If a header is present multiple times
  25. * then the value is an array of all the values.
  26. *
  27. * @param string $content The content of the response
  28. * @param integer $status The response status code
  29. * @param array $headers An array of headers
  30. */
  31. public function __construct($content = '', $status = 200, array $headers = array())
  32. {
  33. $this->content = $content;
  34. $this->status = $status;
  35. $this->headers = $headers;
  36. }
  37. public function __toString()
  38. {
  39. $headers = '';
  40. foreach ($this->headers as $name => $value) {
  41. $headers .= sprintf("%s: %s\n", $name, $value);
  42. }
  43. return $headers."\n".$this->content;
  44. }
  45. /**
  46. * Gets the response content.
  47. *
  48. * @return string The response content
  49. */
  50. public function getContent()
  51. {
  52. return $this->content;
  53. }
  54. /**
  55. * Gets the response status code.
  56. *
  57. * @return integer The response status code
  58. */
  59. public function getStatus()
  60. {
  61. return $this->status;
  62. }
  63. /**
  64. * Gets the response headers.
  65. *
  66. * @return array The response headers
  67. */
  68. public function getHeaders()
  69. {
  70. return $this->headers;
  71. }
  72. /**
  73. * Gets a response header.
  74. *
  75. * @param string $header The header name
  76. * @param Boolean $first Whether to return the first value or all header values
  77. *
  78. * @return string|array The first header value if $first is true, an array of values otherwise
  79. */
  80. public function getHeader($header, $first = true)
  81. {
  82. foreach ($this->headers as $key => $value) {
  83. if (str_replace('-', '_', strtolower($key)) == str_replace('-', '_', strtolower($header))) {
  84. if ($first) {
  85. return is_array($value) ? (count($value) ? $value[0] : '') : $value;
  86. } else {
  87. return is_array($value) ? $value : array($value);
  88. }
  89. }
  90. }
  91. return $first ? null : array();
  92. }
  93. }