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