Stream.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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()
  24. {
  25. return $this->stringContent;
  26. }
  27. public function close()
  28. {
  29. }
  30. public function detach()
  31. {
  32. return fopen('data://text/plain,'.$this->stringContent, 'r');
  33. }
  34. public function getSize()
  35. {
  36. }
  37. public function tell()
  38. {
  39. return 0;
  40. }
  41. public function eof()
  42. {
  43. return $this->eof;
  44. }
  45. public function isSeekable()
  46. {
  47. return true;
  48. }
  49. public function seek($offset, $whence = SEEK_SET)
  50. {
  51. }
  52. public function rewind()
  53. {
  54. $this->eof = false;
  55. }
  56. public function isWritable()
  57. {
  58. return false;
  59. }
  60. public function write($string)
  61. {
  62. }
  63. public function isReadable()
  64. {
  65. return true;
  66. }
  67. public function read($length)
  68. {
  69. $this->eof = true;
  70. return $this->stringContent;
  71. }
  72. public function getContents()
  73. {
  74. return $this->stringContent;
  75. }
  76. public function getMetadata($key = null)
  77. {
  78. }
  79. }