PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / vendor_prefixed / guzzlehttp / psr7 / src / FnStream.php

FnStream.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.5, at vendor_prefixed/guzzlehttp/psr7/src/FnStream.php

165 lines 5.5 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 YoastSEO_Vendor\GuzzleHttp\Psr7;
5
6 use YoastSEO_Vendor\Psr\Http\Message\StreamInterface;
7 /**
8 * Compose stream implementations based on a hash of callables.
9 *
10 * Allows for easy testing and extension of a provided stream without needing
11 * to create a concrete class for a simple extension point.
12 */
13 #[\AllowDynamicProperties]
14 final class FnStream implements \YoastSEO_Vendor\Psr\Http\Message\StreamInterface
15 {
16 private const SLOTS = ['__toString', 'close', 'detach', 'rewind', 'getSize', 'tell', 'eof', 'isSeekable', 'seek', 'isWritable', 'write', 'isReadable', 'read', 'getContents', 'getMetadata'];
17 /** @var array<string, callable> */
18 private $methods;
19 /**
20 * @param array<string, callable> $methods Hash of method name to a callable.
21 */
22 public function __construct(array $methods)
23 {
24 $this->methods = $methods;
25 // Create the callables on the class
26 foreach ($methods as $name => $fn) {
27 $this->{'_fn_' . $name} = $fn;
28 }
29 }
30 /**
31 * Lazily determine which methods are not implemented.
32 *
33 * @throws \BadMethodCallException
34 */
35 public function __get(string $name) : void
36 {
37 throw new \BadMethodCallException(\str_replace('_fn_', '', $name) . '() is not implemented in the FnStream');
38 }
39 /**
40 * The close method is called on the underlying stream only if possible.
41 */
42 public function __destruct()
43 {
44 if (isset($this->_fn_close)) {
45 ($this->_fn_close)();
46 }
47 }
48 /**
49 * An unserialize would allow the __destruct to run when the unserialized value goes out of scope.
50 *
51 * @throws \LogicException
52 */
53 public function __wakeup() : void
54 {
55 throw new \LogicException('FnStream should never be unserialized');
56 }
57 /**
58 * Adds custom functionality to an underlying stream by intercepting
59 * specific method calls.
60 *
61 * @param StreamInterface $stream Stream to decorate
62 * @param array<string, callable> $methods Hash of method name to a callable
63 *
64 * @return FnStream
65 */
66 public static function decorate(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream, array $methods)
67 {
68 // If any of the required methods were not provided, then simply
69 // proxy to the decorated stream.
70 foreach (\array_diff(self::SLOTS, \array_keys($methods)) as $diff) {
71 /** @var callable $callable */
72 $callable = [$stream, $diff];
73 $methods[$diff] = $callable;
74 }
75 return new self($methods);
76 }
77 public function __toString() : string
78 {
79 try {
80 /** @var string */
81 return ($this->_fn___toString)();
82 } catch (\Throwable $e) {
83 if (\PHP_VERSION_ID >= 70400) {
84 throw $e;
85 }
86 \trigger_error(\sprintf('%s::__toString exception: %s', self::class, (string) $e), \E_USER_ERROR);
87 return '';
88 }
89 }
90 public function close() : void
91 {
92 ($this->_fn_close)();
93 }
94 public function detach()
95 {
96 return ($this->_fn_detach)();
97 }
98 public function getSize() : ?int
99 {
100 return ($this->_fn_getSize)();
101 }
102 public function tell() : int
103 {
104 return ($this->_fn_tell)();
105 }
106 public function eof() : bool
107 {
108 return ($this->_fn_eof)();
109 }
110 public function isSeekable() : bool
111 {
112 return ($this->_fn_isSeekable)();
113 }
114 public function rewind() : void
115 {
116 ($this->_fn_rewind)();
117 }
118 public function seek($offset, $whence = \SEEK_SET) : void
119 {
120 if (!\is_int($offset)) {
121 \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/psr7', '2.11', 'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $offset.', \get_debug_type($offset));
122 }
123 if (!\is_int($whence)) {
124 \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/psr7', '2.11', 'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $whence.', \get_debug_type($whence));
125 }
126 ($this->_fn_seek)($offset, $whence);
127 }
128 public function isWritable() : bool
129 {
130 return ($this->_fn_isWritable)();
131 }
132 public function write($string) : int
133 {
134 if (!\is_string($string)) {
135 \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/psr7', '2.11', 'Passing %s to StreamInterface::write() is deprecated; guzzlehttp/psr7 3.0 requires string for $string.', \get_debug_type($string));
136 }
137 return ($this->_fn_write)($string);
138 }
139 public function isReadable() : bool
140 {
141 return ($this->_fn_isReadable)();
142 }
143 public function read($length) : string
144 {
145 if (!\is_int($length)) {
146 \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/psr7', '2.11', 'Passing %s to StreamInterface::read() is deprecated; guzzlehttp/psr7 3.0 requires int for $length.', \get_debug_type($length));
147 }
148 return ($this->_fn_read)($length);
149 }
150 public function getContents() : string
151 {
152 return ($this->_fn_getContents)();
153 }
154 /**
155 * @return mixed
156 */
157 public function getMetadata($key = null)
158 {
159 if ($key !== null && !\is_string($key)) {
160 \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/psr7', '2.11', 'Passing %s to StreamInterface::getMetadata() is deprecated; guzzlehttp/psr7 3.0 requires string|null for $key.', \get_debug_type($key));
161 }
162 return ($this->_fn_getMetadata)($key);
163 }
164 }
165