Message.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 = $body ?? new Stream();
  28. }
  29. public function getProtocolVersion(): string
  30. {
  31. return $this->version;
  32. }
  33. /**
  34. * {@inheritdoc}
  35. *
  36. * @return static
  37. */
  38. public function withProtocolVersion($version)
  39. {
  40. throw new \BadMethodCallException('Not implemented.');
  41. }
  42. public function getHeaders(): array
  43. {
  44. return $this->headers;
  45. }
  46. public function hasHeader($name): bool
  47. {
  48. return isset($this->headers[$name]);
  49. }
  50. public function getHeader($name): array
  51. {
  52. return $this->hasHeader($name) ? $this->headers[$name] : [];
  53. }
  54. public function getHeaderLine($name): string
  55. {
  56. return $this->hasHeader($name) ? implode(',', $this->headers[$name]) : '';
  57. }
  58. /**
  59. * {@inheritdoc}
  60. *
  61. * @return static
  62. */
  63. public function withHeader($name, $value)
  64. {
  65. $this->headers[$name] = (array) $value;
  66. return $this;
  67. }
  68. /**
  69. * {@inheritdoc}
  70. *
  71. * @return static
  72. */
  73. public function withAddedHeader($name, $value)
  74. {
  75. throw new \BadMethodCallException('Not implemented.');
  76. }
  77. /**
  78. * {@inheritdoc}
  79. *
  80. * @return static
  81. */
  82. public function withoutHeader($name)
  83. {
  84. unset($this->headers[$name]);
  85. return $this;
  86. }
  87. public function getBody(): StreamInterface
  88. {
  89. return $this->body;
  90. }
  91. /**
  92. * {@inheritdoc}
  93. *
  94. * @return static
  95. */
  96. public function withBody(StreamInterface $body)
  97. {
  98. throw new \BadMethodCallException('Not implemented.');
  99. }
  100. }