Open Journal Systems  3.3.0
StreamWrapper.php
1 <?php
2 namespace GuzzleHttp\Psr7;
3 
5 
10 {
12  public $context;
13 
15  private $stream;
16 
18  private $mode;
19 
28  public static function getResource(StreamInterface $stream)
29  {
31 
32  if ($stream->isReadable()) {
33  $mode = $stream->isWritable() ? 'r+' : 'r';
34  } elseif ($stream->isWritable()) {
35  $mode = 'w';
36  } else {
37  throw new \InvalidArgumentException('The stream must be readable, '
38  . 'writable, or both.');
39  }
40 
41  return fopen('guzzle://stream', $mode, null, self::createStreamContext($stream));
42  }
43 
51  public static function createStreamContext(StreamInterface $stream)
52  {
53  return stream_context_create([
54  'guzzle' => ['stream' => $stream]
55  ]);
56  }
57 
61  public static function register()
62  {
63  if (!in_array('guzzle', stream_get_wrappers())) {
64  stream_wrapper_register('guzzle', __CLASS__);
65  }
66  }
67 
68  public function stream_open($path, $mode, $options, &$opened_path)
69  {
70  $options = stream_context_get_options($this->context);
71 
72  if (!isset($options['guzzle']['stream'])) {
73  return false;
74  }
75 
76  $this->mode = $mode;
77  $this->stream = $options['guzzle']['stream'];
78 
79  return true;
80  }
81 
82  public function stream_read($count)
83  {
84  return $this->stream->read($count);
85  }
86 
87  public function stream_write($data)
88  {
89  return (int) $this->stream->write($data);
90  }
91 
92  public function stream_tell()
93  {
94  return $this->stream->tell();
95  }
96 
97  public function stream_eof()
98  {
99  return $this->stream->eof();
100  }
101 
102  public function stream_seek($offset, $whence)
103  {
104  $this->stream->seek($offset, $whence);
105 
106  return true;
107  }
108 
109  public function stream_cast($cast_as)
110  {
111  $stream = clone($this->stream);
112 
113  return $stream->detach();
114  }
115 
116  public function stream_stat()
117  {
118  static $modeMap = [
119  'r' => 33060,
120  'rb' => 33060,
121  'r+' => 33206,
122  'w' => 33188,
123  'wb' => 33188
124  ];
125 
126  return [
127  'dev' => 0,
128  'ino' => 0,
129  'mode' => $modeMap[$this->mode],
130  'nlink' => 0,
131  'uid' => 0,
132  'gid' => 0,
133  'rdev' => 0,
134  'size' => $this->stream->getSize() ?: 0,
135  'atime' => 0,
136  'mtime' => 0,
137  'ctime' => 0,
138  'blksize' => 0,
139  'blocks' => 0
140  ];
141  }
142 
143  public function url_stat($path, $flags)
144  {
145  return [
146  'dev' => 0,
147  'ino' => 0,
148  'mode' => 0,
149  'nlink' => 0,
150  'uid' => 0,
151  'gid' => 0,
152  'rdev' => 0,
153  'size' => 0,
154  'atime' => 0,
155  'mtime' => 0,
156  'ctime' => 0,
157  'blksize' => 0,
158  'blocks' => 0
159  ];
160  }
161 }
GuzzleHttp\Psr7\StreamWrapper\createStreamContext
static createStreamContext(StreamInterface $stream)
Definition: StreamWrapper.php:60
Psr\Http\Message\StreamInterface
Definition: vendor/psr/http-message/src/StreamInterface.php:12
GuzzleHttp\Psr7\StreamWrapper\stream_read
stream_read($count)
Definition: StreamWrapper.php:91
GuzzleHttp\Psr7\StreamWrapper\url_stat
url_stat($path, $flags)
Definition: StreamWrapper.php:152
GuzzleHttp\Psr7
Definition: AppendStream.php:2
GuzzleHttp\Psr7\StreamWrapper\getResource
static getResource(StreamInterface $stream)
Definition: StreamWrapper.php:37
GuzzleHttp\Psr7\StreamWrapper
Definition: StreamWrapper.php:9
GuzzleHttp\Psr7\StreamWrapper\stream_seek
stream_seek($offset, $whence)
Definition: StreamWrapper.php:111
GuzzleHttp\Psr7\StreamWrapper\$context
$context
Definition: StreamWrapper.php:15
GuzzleHttp\Psr7\StreamWrapper\stream_open
stream_open($path, $mode, $options, &$opened_path)
Definition: StreamWrapper.php:77
GuzzleHttp\Psr7\StreamWrapper\register
static register()
Definition: StreamWrapper.php:70
GuzzleHttp\Psr7\StreamWrapper\stream_tell
stream_tell()
Definition: StreamWrapper.php:101
GuzzleHttp\Psr7\StreamWrapper\stream_write
stream_write($data)
Definition: StreamWrapper.php:96
GuzzleHttp\Psr7\StreamWrapper\stream_cast
stream_cast($cast_as)
Definition: StreamWrapper.php:118
GuzzleHttp\Psr7\StreamWrapper\stream_stat
stream_stat()
Definition: StreamWrapper.php:125
GuzzleHttp\Psr7\StreamWrapper\stream_eof
stream_eof()
Definition: StreamWrapper.php:106