Message.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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\Bridge\PsrHttpMessage\Tests\Fixtures;
  11. use Psr\Http\Message\MessageInterface;
  12. use Psr\Http\Message\StreamInterface;
  13. /**
  14. * Message.
  15. *
  16. * @author Kévin Dunglas <dunglas@gmail.com>
  17. */
  18. class Message implements MessageInterface
  19. {
  20. private $version = '1.1';
  21. private $headers = [];
  22. private $body;
  23. public function __construct($version = '1.1', array $headers = [], StreamInterface $body = null)
  24. {
  25. $this->version = $version;
  26. $this->headers = $headers;
  27. $this->body = null === $body ? new Stream() : $body;
  28. }
  29. public function getProtocolVersion()
  30. {
  31. return $this->version;
  32. }
  33. public function withProtocolVersion($version)
  34. {
  35. throw new \BadMethodCallException('Not implemented.');
  36. }
  37. public function getHeaders()
  38. {
  39. return $this->headers;
  40. }
  41. public function hasHeader($name)
  42. {
  43. return isset($this->headers[$name]);
  44. }
  45. public function getHeader($name)
  46. {
  47. return $this->hasHeader($name) ? $this->headers[$name] : [];
  48. }
  49. public function getHeaderLine($name)
  50. {
  51. return $this->hasHeader($name) ? implode(',', $this->headers[$name]) : '';
  52. }
  53. public function withHeader($name, $value)
  54. {
  55. $this->headers[$name] = (array) $value;
  56. return $this;
  57. }
  58. public function withAddedHeader($name, $value)
  59. {
  60. throw new \BadMethodCallException('Not implemented.');
  61. }
  62. public function withoutHeader($name)
  63. {
  64. unset($this->headers[$name]);
  65. return $this;
  66. }
  67. public function getBody()
  68. {
  69. return $this->body;
  70. }
  71. public function withBody(StreamInterface $body)
  72. {
  73. throw new \BadMethodCallException('Not implemented.');
  74. }
  75. }