PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.2
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.2
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 18.2, at vendor_prefixed/guzzlehttp/psr7/src/FnStream.php

137 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YoastSEO_Vendor\GuzzleHttp\Psr7;
4
5 use YoastSEO_Vendor\Psr\Http\Message\StreamInterface;
6 /**
7 * Compose stream implementations based on a hash of functions.
8 *
9 * Allows for easy testing and extension of a provided stream without needing
10 * to create a concrete class for a simple extension point.
11 *
12 * @final
13 */
14 class FnStream implements \YoastSEO_Vendor\Psr\Http\Message\StreamInterface
15 {
16 /** @var array */
17 private $methods;
18 /** @var array Methods that must be implemented in the given array */
19 private static $slots = ['__toString', 'close', 'detach', 'rewind', 'getSize', 'tell', 'eof', 'isSeekable', 'seek', 'isWritable', 'write', 'isReadable', 'read', 'getContents', 'getMetadata'];
20 /**
21 * @param array $methods Hash of method name to a callable.
22 */
23 public function __construct(array $methods)
24 {
25 $this->methods = $methods;
26 // Create the functions on the class
27 foreach ($methods as $name => $fn) {
28 $this->{'_fn_' . $name} = $fn;
29 }
30 }
31 /**
32 * Lazily determine which methods are not implemented.
33 *
34 * @throws \BadMethodCallException
35 */
36 public function __get($name)
37 {
38 throw new \BadMethodCallException(\str_replace('_fn_', '', $name) . '() is not implemented in the FnStream');
39 }
40 /**
41 * The close method is called on the underlying stream only if possible.
42 */
43 public function __destruct()
44 {
45 if (isset($this->_fn_close)) {
46 \call_user_func($this->_fn_close);
47 }
48 }
49 /**
50 * An unserialize would allow the __destruct to run when the unserialized value goes out of scope.
51 *
52 * @throws \LogicException
53 */
54 public function __wakeup()
55 {
56 throw new \LogicException('FnStream should never be unserialized');
57 }
58 /**
59 * Adds custom functionality to an underlying stream by intercepting
60 * specific method calls.
61 *
62 * @param StreamInterface $stream Stream to decorate
63 * @param array $methods Hash of method name to a closure
64 *
65 * @return FnStream
66 */
67 public static function decorate(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream, array $methods)
68 {
69 // If any of the required methods were not provided, then simply
70 // proxy to the decorated stream.
71 foreach (\array_diff(self::$slots, \array_keys($methods)) as $diff) {
72 $methods[$diff] = [$stream, $diff];
73 }
74 return new self($methods);
75 }
76 public function __toString()
77 {
78 return \call_user_func($this->_fn___toString);
79 }
80 public function close()
81 {
82 return \call_user_func($this->_fn_close);
83 }
84 public function detach()
85 {
86 return \call_user_func($this->_fn_detach);
87 }
88 public function getSize()
89 {
90 return \call_user_func($this->_fn_getSize);
91 }
92 public function tell()
93 {
94 return \call_user_func($this->_fn_tell);
95 }
96 public function eof()
97 {
98 return \call_user_func($this->_fn_eof);
99 }
100 public function isSeekable()
101 {
102 return \call_user_func($this->_fn_isSeekable);
103 }
104 public function rewind()
105 {
106 \call_user_func($this->_fn_rewind);
107 }
108 public function seek($offset, $whence = \SEEK_SET)
109 {
110 \call_user_func($this->_fn_seek, $offset, $whence);
111 }
112 public function isWritable()
113 {
114 return \call_user_func($this->_fn_isWritable);
115 }
116 public function write($string)
117 {
118 return \call_user_func($this->_fn_write, $string);
119 }
120 public function isReadable()
121 {
122 return \call_user_func($this->_fn_isReadable);
123 }
124 public function read($length)
125 {
126 return \call_user_func($this->_fn_read, $length);
127 }
128 public function getContents()
129 {
130 return \call_user_func($this->_fn_getContents);
131 }
132 public function getMetadata($key = null)
133 {
134 return \call_user_func($this->_fn_getMetadata, $key);
135 }
136 }
137