Open Journal Systems  3.3.0
FnStream.php
1 <?php
2 namespace GuzzleHttp\Psr7;
3 
5 
12 class FnStream implements StreamInterface
13 {
15  private $methods;
16 
18  private static $slots = ['__toString', 'close', 'detach', 'rewind',
19  'getSize', 'tell', 'eof', 'isSeekable', 'seek', 'isWritable', 'write',
20  'isReadable', 'read', 'getContents', 'getMetadata'];
21 
25  public function __construct(array $methods)
26  {
27  $this->methods = $methods;
28 
29  // Create the functions on the class
30  foreach ($methods as $name => $fn) {
31  $this->{'_fn_' . $name} = $fn;
32  }
33  }
34 
39  public function __get($name)
40  {
41  throw new \BadMethodCallException(str_replace('_fn_', '', $name)
42  . '() is not implemented in the FnStream');
43  }
44 
48  public function __destruct()
49  {
50  if (isset($this->_fn_close)) {
51  call_user_func($this->_fn_close);
52  }
53  }
54 
59  public function __wakeup()
60  {
61  throw new \LogicException('FnStream should never be unserialized');
62  }
63 
73  public static function decorate(StreamInterface $stream, array $methods)
74  {
75  // If any of the required methods were not provided, then simply
76  // proxy to the decorated stream.
77  foreach (array_diff(self::$slots, array_keys($methods)) as $diff) {
78  $methods[$diff] = [$stream, $diff];
79  }
80 
81  return new self($methods);
82  }
83 
84  public function __toString()
85  {
86  return call_user_func($this->_fn___toString);
87  }
88 
89  public function close()
90  {
91  return call_user_func($this->_fn_close);
92  }
93 
94  public function detach()
95  {
96  return call_user_func($this->_fn_detach);
97  }
98 
99  public function getSize()
100  {
101  return call_user_func($this->_fn_getSize);
102  }
103 
104  public function tell()
105  {
106  return call_user_func($this->_fn_tell);
107  }
108 
109  public function eof()
110  {
111  return call_user_func($this->_fn_eof);
112  }
113 
114  public function isSeekable()
115  {
116  return call_user_func($this->_fn_isSeekable);
117  }
118 
119  public function rewind()
120  {
121  call_user_func($this->_fn_rewind);
122  }
123 
124  public function seek($offset, $whence = SEEK_SET)
125  {
126  call_user_func($this->_fn_seek, $offset, $whence);
127  }
128 
129  public function isWritable()
130  {
131  return call_user_func($this->_fn_isWritable);
132  }
133 
134  public function write($string)
135  {
136  return call_user_func($this->_fn_write, $string);
137  }
138 
139  public function isReadable()
140  {
141  return call_user_func($this->_fn_isReadable);
142  }
143 
144  public function read($length)
145  {
146  return call_user_func($this->_fn_read, $length);
147  }
148 
149  public function getContents()
150  {
151  return call_user_func($this->_fn_getContents);
152  }
153 
154  public function getMetadata($key = null)
155  {
156  return call_user_func($this->_fn_getMetadata, $key);
157  }
158 }
GuzzleHttp\Psr7\FnStream\write
write($string)
Definition: FnStream.php:137
GuzzleHttp\Psr7\FnStream\__get
__get($name)
Definition: FnStream.php:42
GuzzleHttp\Psr7\FnStream\rewind
rewind()
Definition: FnStream.php:122
Psr\Http\Message\StreamInterface
Definition: vendor/psr/http-message/src/StreamInterface.php:12
GuzzleHttp\Psr7\FnStream\__toString
__toString()
Definition: FnStream.php:87
GuzzleHttp\Psr7\FnStream\__destruct
__destruct()
Definition: FnStream.php:51
GuzzleHttp\Psr7\FnStream\decorate
static decorate(StreamInterface $stream, array $methods)
Definition: FnStream.php:76
GuzzleHttp\Psr7\FnStream\getMetadata
getMetadata($key=null)
Definition: FnStream.php:157
GuzzleHttp\Psr7\FnStream\detach
detach()
Definition: FnStream.php:97
GuzzleHttp\Psr7
Definition: AppendStream.php:2
GuzzleHttp\Psr7\FnStream\tell
tell()
Definition: FnStream.php:107
GuzzleHttp\Psr7\FnStream\getContents
getContents()
Definition: FnStream.php:152
GuzzleHttp\Psr7\FnStream\isReadable
isReadable()
Definition: FnStream.php:142
GuzzleHttp\Psr7\FnStream\__construct
__construct(array $methods)
Definition: FnStream.php:28
GuzzleHttp\Psr7\FnStream\__wakeup
__wakeup()
Definition: FnStream.php:62
GuzzleHttp\Psr7\FnStream
Definition: FnStream.php:12
GuzzleHttp\Psr7\FnStream\seek
seek($offset, $whence=SEEK_SET)
Definition: FnStream.php:127
GuzzleHttp\Psr7\FnStream\isSeekable
isSeekable()
Definition: FnStream.php:117
GuzzleHttp\Psr7\FnStream\read
read($length)
Definition: FnStream.php:147
GuzzleHttp\Psr7\FnStream\close
close()
Definition: FnStream.php:92
GuzzleHttp\Psr7\FnStream\getSize
getSize()
Definition: FnStream.php:102
GuzzleHttp\Psr7\FnStream\eof
eof()
Definition: FnStream.php:112
GuzzleHttp\Psr7\FnStream\isWritable
isWritable()
Definition: FnStream.php:132