PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / vendor / guzzlehttp / psr7 / src / LazyOpenStream.php

LazyOpenStream.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.13, at vendor/guzzlehttp/psr7/src/LazyOpenStream.php

50 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
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 }
50