酒店预订平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

43 行
900 B

  1. <?php
  2. namespace GuzzleHttp\Psr7;
  3. use Psr\Http\Message\StreamInterface;
  4. /**
  5. * Lazily reads or writes to a file that is opened only after an IO operation
  6. * take place on the stream.
  7. *
  8. * @final
  9. */
  10. class LazyOpenStream implements StreamInterface
  11. {
  12. use StreamDecoratorTrait;
  13. /** @var string File to open */
  14. private $filename;
  15. /** @var string */
  16. private $mode;
  17. /**
  18. * @param string $filename File to lazily open
  19. * @param string $mode fopen mode to use when opening the stream
  20. */
  21. public function __construct($filename, $mode)
  22. {
  23. $this->filename = $filename;
  24. $this->mode = $mode;
  25. }
  26. /**
  27. * Creates the underlying stream lazily when required.
  28. *
  29. * @return StreamInterface
  30. */
  31. protected function createStream()
  32. {
  33. return Utils::streamFor(Utils::tryFopen($this->filename, $this->mode));
  34. }
  35. }