Stream.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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\StreamInterface;
  12. /**
  13. * @author Kévin Dunglas <dunglas@gmail.com>
  14. */
  15. class Stream implements StreamInterface
  16. {
  17. private $stringContent;
  18. private $eof = true;
  19. public function __construct($stringContent = '')
  20. {
  21. $this->stringContent = $stringContent;
  22. }
  23. public function __toString(): string
  24. {
  25. return $this->stringContent;
  26. }
  27. public function close(): void
  28. {
  29. }
  30. public function detach()
  31. {
  32. return fopen('data://text/plain,'.$this->stringContent, 'r');
  33. }
  34. public function getSize(): ?int
  35. {
  36. return null;
  37. }
  38. public function tell(): int
  39. {
  40. return 0;
  41. }
  42. public function eof(): bool
  43. {
  44. return $this->eof;
  45. }
  46. public function isSeekable(): bool
  47. {
  48. return true;
  49. }
  50. public function seek($offset, $whence = \SEEK_SET): void
  51. {
  52. }
  53. public function rewind(): void
  54. {
  55. $this->eof = false;
  56. }
  57. public function isWritable(): bool
  58. {
  59. return false;
  60. }
  61. public function write($string): int
  62. {
  63. return \strlen($string);
  64. }
  65. public function isReadable(): bool
  66. {
  67. return true;
  68. }
  69. public function read($length): string
  70. {
  71. $this->eof = true;
  72. return $this->stringContent;
  73. }
  74. public function getContents(): string
  75. {
  76. return $this->stringContent;
  77. }
  78. /**
  79. * {@inheritdoc}
  80. *
  81. * @return mixed
  82. */
  83. public function getMetadata($key = null)
  84. {
  85. return null;
  86. }
  87. }