PluginProbe
Media Cloud Sync / 1.3.0
Media Cloud Sync v1.3.0
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / GuzzleHttp / Psr7 / LazyOpenStream.php

LazyOpenStream.php in Media Cloud Sync 1.3.0, at includes/sdk/s3/GuzzleHttp/Psr7/LazyOpenStream.php

42 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7;
5
6 use Dudlewebs\WPMCS\s3\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 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() : StreamInterface
38 {
39 return Utils::streamFor(Utils::tryFopen($this->filename, $this->mode));
40 }
41 }
42