ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
StreamWrapper.php
Go to the documentation of this file.
1<?php
2namespace 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, stream_context_create([
42 'guzzle' => ['stream' => $stream]
43 ]));
44 }
45
49 public static function register()
50 {
51 if (!in_array('guzzle', stream_get_wrappers())) {
52 stream_wrapper_register('guzzle', __CLASS__);
53 }
54 }
55
56 public function stream_open($path, $mode, $options, &$opened_path)
57 {
58 $options = stream_context_get_options($this->context);
59
60 if (!isset($options['guzzle']['stream'])) {
61 return false;
62 }
63
64 $this->mode = $mode;
65 $this->stream = $options['guzzle']['stream'];
66
67 return true;
68 }
69
70 public function stream_read($count)
71 {
72 return $this->stream->read($count);
73 }
74
75 public function stream_write($data)
76 {
77 return (int) $this->stream->write($data);
78 }
79
80 public function stream_tell()
81 {
82 return $this->stream->tell();
83 }
84
85 public function stream_eof()
86 {
87 return $this->stream->eof();
88 }
89
90 public function stream_seek($offset, $whence)
91 {
92 $this->stream->seek($offset, $whence);
93
94 return true;
95 }
96
97 public function stream_stat()
98 {
99 static $modeMap = [
100 'r' => 33060,
101 'r+' => 33206,
102 'w' => 33188
103 ];
104
105 return [
106 'dev' => 0,
107 'ino' => 0,
108 'mode' => $modeMap[$this->mode],
109 'nlink' => 0,
110 'uid' => 0,
111 'gid' => 0,
112 'rdev' => 0,
113 'size' => $this->stream->getSize() ?: 0,
114 'atime' => 0,
115 'mtime' => 0,
116 'ctime' => 0,
117 'blksize' => 0,
118 'blocks' => 0
119 ];
120 }
121}
$path
Definition: aliased.php:25
An exception for terminatinating execution or to throw for unit testing.
Converts Guzzle streams into PHP stream resources.
static getResource(StreamInterface $stream)
Returns a resource representing the stream.
stream_seek($offset, $whence)
stream_open($path, $mode, $options, &$opened_path)
static register()
Registers the stream wrapper if needed.
Describes a data stream.
$data
Definition: bench.php:6