| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,49 @@ |
| 1 |
+<?php |
|
| 2 |
+ |
|
| 3 |
+declare(strict_types=1); |
|
| 4 |
+ |
|
| 5 |
+namespace GuzzleHttp\Psr7; |
|
| 6 |
+ |
|
| 7 |
+use Psr\Http\Message\StreamInterface; |
|
| 8 |
+ |
|
| 9 |
+/** |
|
| 10 |
+ * Lazily reads or writes to a file that is opened only after an IO operation |
|
| 11 |
+ * take place on the stream. |
|
| 12 |
+ */ |
|
| 13 |
+final class LazyOpenStream implements StreamInterface |
|
| 14 |
+{
|
|
| 15 |
+ use StreamDecoratorTrait; |
|
| 16 |
+ |
|
| 17 |
+ /** @var string */ |
|
| 18 |
+ private $filename; |
|
| 19 |
+ |
|
| 20 |
+ /** @var string */ |
|
| 21 |
+ private $mode; |
|
| 22 |
+ |
|
| 23 |
+ /** |
|
| 24 |
+ * @var StreamInterface |
|
| 25 |
+ */ |
|
| 26 |
+ private $stream; |
|
| 27 |
+ |
|
| 28 |
+ /** |
|
| 29 |
+ * @param string $filename File to lazily open |
|
| 30 |
+ * @param string $mode fopen mode to use when opening the stream |
|
| 31 |
+ */ |
|
| 32 |
+ public function __construct(string $filename, string $mode) |
|
| 33 |
+ {
|
|
| 34 |
+ $this->filename = $filename; |
|
| 35 |
+ $this->mode = $mode; |
|
| 36 |
+ |
|
| 37 |
+ // unsetting the property forces the first access to go through |
|
| 38 |
+ // __get(). |
|
| 39 |
+ unset($this->stream); |
|
| 40 |
+ } |
|
| 41 |
+ |
|
| 42 |
+ /** |
|
| 43 |
+ * Creates the underlying stream lazily when required. |
|
| 44 |
+ */ |
|
| 45 |
+ protected function createStream(): StreamInterface |
|
| 46 |
+ {
|
|
| 47 |
+ return Utils::streamFor(Utils::tryFopen($this->filename, $this->mode)); |
|
| 48 |
+ } |
|
| 49 |
+} |
| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,40 +0,0 @@ |
| 1 |
-<?php |
|
| 2 |
- |
|
| 3 |
-namespace GuzzleHttp\Psr7; |
|
| 4 |
- |
|
| 5 |
-use Psr\Http\Message\StreamInterface; |
|
| 6 |
- |
|
| 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 |
-class LazyOpenStream implements StreamInterface |
|
| 12 |
-{
|
|
| 13 |
- use StreamDecoratorTrait; |
|
| 14 |
- |
|
| 15 |
- /** @var string File to open */ |
|
| 16 |
- private $filename; |
|
| 17 |
- |
|
| 18 |
- /** @var string $mode */ |
|
| 19 |
- private $mode; |
|
| 20 |
- |
|
| 21 |
- /** |
|
| 22 |
- * @param string $filename File to lazily open |
|
| 23 |
- * @param string $mode fopen mode to use when opening the stream |
|
| 24 |
- */ |
|
| 25 |
- public function __construct($filename, $mode) |
|
| 26 |
- {
|
|
| 27 |
- $this->filename = $filename; |
|
| 28 |
- $this->mode = $mode; |
|
| 29 |
- } |
|
| 30 |
- |
|
| 31 |
- /** |
|
| 32 |
- * Creates the underlying stream lazily when required. |
|
| 33 |
- * |
|
| 34 |
- * @return StreamInterface |
|
| 35 |
- */ |
|
| 36 |
- protected function createStream() |
|
| 37 |
- {
|
|
| 38 |
- return Utils::streamFor(Utils::tryFopen($this->filename, $this->mode)); |
|
| 39 |
- } |
|
| 40 |
-} |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,40 @@ |
| 1 |
+<?php |
|
| 2 |
+ |
|
| 3 |
+namespace GuzzleHttp\Psr7; |
|
| 4 |
+ |
|
| 5 |
+use Psr\Http\Message\StreamInterface; |
|
| 6 |
+ |
|
| 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 |
+class LazyOpenStream implements StreamInterface |
|
| 12 |
+{
|
|
| 13 |
+ use StreamDecoratorTrait; |
|
| 14 |
+ |
|
| 15 |
+ /** @var string File to open */ |
|
| 16 |
+ private $filename; |
|
| 17 |
+ |
|
| 18 |
+ /** @var string $mode */ |
|
| 19 |
+ private $mode; |
|
| 20 |
+ |
|
| 21 |
+ /** |
|
| 22 |
+ * @param string $filename File to lazily open |
|
| 23 |
+ * @param string $mode fopen mode to use when opening the stream |
|
| 24 |
+ */ |
|
| 25 |
+ public function __construct($filename, $mode) |
|
| 26 |
+ {
|
|
| 27 |
+ $this->filename = $filename; |
|
| 28 |
+ $this->mode = $mode; |
|
| 29 |
+ } |
|
| 30 |
+ |
|
| 31 |
+ /** |
|
| 32 |
+ * Creates the underlying stream lazily when required. |
|
| 33 |
+ * |
|
| 34 |
+ * @return StreamInterface |
|
| 35 |
+ */ |
|
| 36 |
+ protected function createStream() |
|
| 37 |
+ {
|
|
| 38 |
+ return Utils::streamFor(Utils::tryFopen($this->filename, $this->mode)); |
|
| 39 |
+ } |
|
| 40 |
+} |