PluginProbe
Media Cloud Sync / 1.2.10
Media Cloud Sync v1.2.10
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 / StreamDecoratorTrait.php

StreamDecoratorTrait.php in Media Cloud Sync 1.2.10, at includes/sdk/s3/GuzzleHttp/Psr7/StreamDecoratorTrait.php

131 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7;
4
5 use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface;
6 /**
7 * Stream decorator trait
8 *
9 * @property StreamInterface stream
10 */
11 trait StreamDecoratorTrait
12 {
13 /**
14 * @param StreamInterface $stream Stream to decorate
15 */
16 public function __construct(StreamInterface $stream)
17 {
18 $this->stream = $stream;
19 }
20 /**
21 * Magic method used to create a new stream if streams are not added in
22 * the constructor of a decorator (e.g., LazyOpenStream).
23 *
24 * @param string $name Name of the property (allows "stream" only).
25 *
26 * @return StreamInterface
27 */
28 public function __get($name)
29 {
30 if ($name == 'stream') {
31 $this->stream = $this->createStream();
32 return $this->stream;
33 }
34 throw new \UnexpectedValueException("{$name} not found on class");
35 }
36 public function __toString()
37 {
38 try {
39 if ($this->isSeekable()) {
40 $this->seek(0);
41 }
42 return $this->getContents();
43 } catch (\Exception $e) {
44 // Really, PHP? https://bugs.php.net/bug.php?id=53648
45 \trigger_error('StreamDecorator::__toString exception: ' . (string) $e, \E_USER_ERROR);
46 return '';
47 }
48 }
49 public function getContents()
50 {
51 return Utils::copyToString($this);
52 }
53 /**
54 * Allow decorators to implement custom methods
55 *
56 * @param string $method Missing method name
57 * @param array $args Method arguments
58 *
59 * @return mixed
60 */
61 public function __call($method, array $args)
62 {
63 $result = \call_user_func_array([$this->stream, $method], $args);
64 // Always return the wrapped object if the result is a return $this
65 return $result === $this->stream ? $this : $result;
66 }
67 public function close()
68 {
69 $this->stream->close();
70 }
71 public function getMetadata($key = null)
72 {
73 return $this->stream->getMetadata($key);
74 }
75 public function detach()
76 {
77 return $this->stream->detach();
78 }
79 public function getSize()
80 {
81 return $this->stream->getSize();
82 }
83 public function eof()
84 {
85 return $this->stream->eof();
86 }
87 public function tell()
88 {
89 return $this->stream->tell();
90 }
91 public function isReadable()
92 {
93 return $this->stream->isReadable();
94 }
95 public function isWritable()
96 {
97 return $this->stream->isWritable();
98 }
99 public function isSeekable()
100 {
101 return $this->stream->isSeekable();
102 }
103 public function rewind()
104 {
105 $this->seek(0);
106 }
107 public function seek($offset, $whence = \SEEK_SET)
108 {
109 $this->stream->seek($offset, $whence);
110 }
111 public function read($length)
112 {
113 return $this->stream->read($length);
114 }
115 public function write($string)
116 {
117 return $this->stream->write($string);
118 }
119 /**
120 * Implement in subclasses to dynamically create streams when requested.
121 *
122 * @return StreamInterface
123 *
124 * @throws \BadMethodCallException
125 */
126 protected function createStream()
127 {
128 throw new \BadMethodCallException('Not implemented');
129 }
130 }
131