annotate vendor/guzzlehttp/psr7/src/LazyOpenStream.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2 namespace GuzzleHttp\Psr7;
Chris@0 3
Chris@0 4 use Psr\Http\Message\StreamInterface;
Chris@0 5
Chris@0 6 /**
Chris@0 7 * Lazily reads or writes to a file that is opened only after an IO operation
Chris@0 8 * take place on the stream.
Chris@0 9 */
Chris@0 10 class LazyOpenStream implements StreamInterface
Chris@0 11 {
Chris@0 12 use StreamDecoratorTrait;
Chris@0 13
Chris@0 14 /** @var string File to open */
Chris@0 15 private $filename;
Chris@0 16
Chris@0 17 /** @var string $mode */
Chris@0 18 private $mode;
Chris@0 19
Chris@0 20 /**
Chris@0 21 * @param string $filename File to lazily open
Chris@0 22 * @param string $mode fopen mode to use when opening the stream
Chris@0 23 */
Chris@0 24 public function __construct($filename, $mode)
Chris@0 25 {
Chris@0 26 $this->filename = $filename;
Chris@0 27 $this->mode = $mode;
Chris@0 28 }
Chris@0 29
Chris@0 30 /**
Chris@0 31 * Creates the underlying stream lazily when required.
Chris@0 32 *
Chris@0 33 * @return StreamInterface
Chris@0 34 */
Chris@0 35 protected function createStream()
Chris@0 36 {
Chris@0 37 return stream_for(try_fopen($this->filename, $this->mode));
Chris@0 38 }
Chris@0 39 }