PluginProbe
Media Cloud Sync / 1.2.9
Media Cloud Sync v1.2.9
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 / StreamWrapper.php

StreamWrapper.php in Media Cloud Sync 1.2.9, at includes/sdk/s3/GuzzleHttp/Psr7/StreamWrapper.php

106 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 * Converts Guzzle streams into PHP stream resources.
8 *
9 * @final
10 */
11 class StreamWrapper
12 {
13 /** @var resource */
14 public $context;
15 /** @var StreamInterface */
16 private $stream;
17 /** @var string r, r+, or w */
18 private $mode;
19 /**
20 * Returns a resource representing the stream.
21 *
22 * @param StreamInterface $stream The stream to get a resource for
23 *
24 * @return resource
25 *
26 * @throws \InvalidArgumentException if stream is not readable or writable
27 */
28 public static function getResource(StreamInterface $stream)
29 {
30 self::register();
31 if ($stream->isReadable()) {
32 $mode = $stream->isWritable() ? 'r+' : 'r';
33 } elseif ($stream->isWritable()) {
34 $mode = 'w';
35 } else {
36 throw new \InvalidArgumentException('The stream must be readable, ' . 'writable, or both.');
37 }
38 return \fopen('guzzle://stream', $mode, null, self::createStreamContext($stream));
39 }
40 /**
41 * Creates a stream context that can be used to open a stream as a php stream resource.
42 *
43 * @param StreamInterface $stream
44 *
45 * @return resource
46 */
47 public static function createStreamContext(StreamInterface $stream)
48 {
49 return \stream_context_create(['guzzle' => ['stream' => $stream]]);
50 }
51 /**
52 * Registers the stream wrapper if needed
53 */
54 public static function register()
55 {
56 if (!\in_array('guzzle', \stream_get_wrappers())) {
57 \stream_wrapper_register('guzzle', __CLASS__);
58 }
59 }
60 public function stream_open($path, $mode, $options, &$opened_path)
61 {
62 $options = \stream_context_get_options($this->context);
63 if (!isset($options['guzzle']['stream'])) {
64 return \false;
65 }
66 $this->mode = $mode;
67 $this->stream = $options['guzzle']['stream'];
68 return \true;
69 }
70 public function stream_read($count)
71 {
72 return $this->stream->read($count);
73 }
74 public function stream_write($data)
75 {
76 return (int) $this->stream->write($data);
77 }
78 public function stream_tell()
79 {
80 return $this->stream->tell();
81 }
82 public function stream_eof()
83 {
84 return $this->stream->eof();
85 }
86 public function stream_seek($offset, $whence)
87 {
88 $this->stream->seek($offset, $whence);
89 return \true;
90 }
91 public function stream_cast($cast_as)
92 {
93 $stream = clone $this->stream;
94 return $stream->detach();
95 }
96 public function stream_stat()
97 {
98 static $modeMap = ['r' => 33060, 'rb' => 33060, 'r+' => 33206, 'w' => 33188, 'wb' => 33188];
99 return ['dev' => 0, 'ino' => 0, 'mode' => $modeMap[$this->mode], 'nlink' => 0, 'uid' => 0, 'gid' => 0, 'rdev' => 0, 'size' => $this->stream->getSize() ?: 0, 'atime' => 0, 'mtime' => 0, 'ctime' => 0, 'blksize' => 0, 'blocks' => 0];
100 }
101 public function url_stat($path, $flags)
102 {
103 return ['dev' => 0, 'ino' => 0, 'mode' => 0, 'nlink' => 0, 'uid' => 0, 'gid' => 0, 'rdev' => 0, 'size' => 0, 'atime' => 0, 'mtime' => 0, 'ctime' => 0, 'blksize' => 0, 'blocks' => 0];
104 }
105 }
106