Exception
2 years ago
AppendStream.php
2 years ago
BufferStream.php
2 years ago
CachingStream.php
2 years ago
DroppingStream.php
2 years ago
FnStream.php
2 years ago
Header.php
2 years ago
HttpFactory.php
2 years ago
InflateStream.php
2 years ago
LazyOpenStream.php
2 years ago
LimitStream.php
2 years ago
Message.php
2 years ago
MessageTrait.php
2 years ago
MimeType.php
2 years ago
MultipartStream.php
2 years ago
NoSeekStream.php
2 years ago
PumpStream.php
2 years ago
Query.php
2 years ago
Request.php
2 years ago
Response.php
2 years ago
Rfc7230.php
2 years ago
ServerRequest.php
2 years ago
Stream.php
2 years ago
StreamDecoratorTrait.php
2 years ago
StreamWrapper.php
2 years ago
UploadedFile.php
2 years ago
Uri.php
2 years ago
UriComparator.php
2 years ago
UriNormalizer.php
2 years ago
UriResolver.php
2 years ago
Utils.php
2 years ago
LazyOpenStream.php
42 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace YoastSEO_Vendor\GuzzleHttp\Psr7; |
| 5 | |
| 6 | use YoastSEO_Vendor\Psr\Http\Message\StreamInterface; |
| 7 | /** |
| 8 | * Lazily reads or writes to a file that is opened only after an IO operation |
| 9 | * take place on the stream. |
| 10 | */ |
| 11 | final class LazyOpenStream implements \YoastSEO_Vendor\Psr\Http\Message\StreamInterface |
| 12 | { |
| 13 | use StreamDecoratorTrait; |
| 14 | /** @var string */ |
| 15 | private $filename; |
| 16 | /** @var string */ |
| 17 | private $mode; |
| 18 | /** |
| 19 | * @var StreamInterface |
| 20 | */ |
| 21 | private $stream; |
| 22 | /** |
| 23 | * @param string $filename File to lazily open |
| 24 | * @param string $mode fopen mode to use when opening the stream |
| 25 | */ |
| 26 | public function __construct(string $filename, string $mode) |
| 27 | { |
| 28 | $this->filename = $filename; |
| 29 | $this->mode = $mode; |
| 30 | // unsetting the property forces the first access to go through |
| 31 | // __get(). |
| 32 | unset($this->stream); |
| 33 | } |
| 34 | /** |
| 35 | * Creates the underlying stream lazily when required. |
| 36 | */ |
| 37 | protected function createStream() : \YoastSEO_Vendor\Psr\Http\Message\StreamInterface |
| 38 | { |
| 39 | return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::streamFor(\YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::tryFopen($this->filename, $this->mode)); |
| 40 | } |
| 41 | } |
| 42 |