Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 10... Línea 10...
10
 * PHP stream implementation.
10
 * PHP stream implementation.
11
 */
11
 */
12
class Stream implements StreamInterface
12
class Stream implements StreamInterface
13
{
13
{
14
    /**
14
    /**
15
     * @see http://php.net/manual/function.fopen.php
15
     * @see https://www.php.net/manual/en/function.fopen.php
16
     * @see http://php.net/manual/en/function.gzopen.php
16
     * @see https://www.php.net/manual/en/function.gzopen.php
17
     */
17
     */
18
    private const READABLE_MODES = '/r|a\+|ab\+|w\+|wb\+|x\+|xb\+|c\+|cb\+/';
18
    private const READABLE_MODES = '/r|a\+|ab\+|w\+|wb\+|x\+|xb\+|c\+|cb\+/';
19
    private const WRITABLE_MODES = '/a|w|r\+|rb\+|rw|x|c/';
19
    private const WRITABLE_MODES = '/a|w|r\+|rb\+|rw|x|c/';
Línea 20... Línea 20...
20
 
20
 
Línea 59... Línea 59...
59
 
59
 
60
        $this->customMetadata = $options['metadata'] ?? [];
60
        $this->customMetadata = $options['metadata'] ?? [];
61
        $this->stream = $stream;
61
        $this->stream = $stream;
62
        $meta = stream_get_meta_data($this->stream);
62
        $meta = stream_get_meta_data($this->stream);
63
        $this->seekable = $meta['seekable'];
63
        $this->seekable = $meta['seekable'];
64
        $this->readable = (bool)preg_match(self::READABLE_MODES, $meta['mode']);
64
        $this->readable = (bool) preg_match(self::READABLE_MODES, $meta['mode']);
65
        $this->writable = (bool)preg_match(self::WRITABLE_MODES, $meta['mode']);
65
        $this->writable = (bool) preg_match(self::WRITABLE_MODES, $meta['mode']);
66
        $this->uri = $this->getMetadata('uri');
66
        $this->uri = $this->getMetadata('uri');
Línea 67... Línea 67...
67
    }
67
    }
68
 
68
 
Línea 78... Línea 78...
78
    {
78
    {
79
        try {
79
        try {
80
            if ($this->isSeekable()) {
80
            if ($this->isSeekable()) {
81
                $this->seek(0);
81
                $this->seek(0);
82
            }
82
            }
-
 
83
 
83
            return $this->getContents();
84
            return $this->getContents();
84
        } catch (\Throwable $e) {
85
        } catch (\Throwable $e) {
85
            if (\PHP_VERSION_ID >= 70400) {
86
            if (\PHP_VERSION_ID >= 70400) {
86
                throw $e;
87
                throw $e;
87
            }
88
            }
88
            trigger_error(sprintf('%s::__toString exception: %s', self::class, (string) $e), E_USER_ERROR);
89
            trigger_error(sprintf('%s::__toString exception: %s', self::class, (string) $e), E_USER_ERROR);
-
 
90
 
89
            return '';
91
            return '';
90
        }
92
        }
91
    }
93
    }
Línea 92... Línea 94...
92
 
94
 
Línea 143... Línea 145...
143
        }
145
        }
Línea 144... Línea 146...
144
 
146
 
145
        $stats = fstat($this->stream);
147
        $stats = fstat($this->stream);
146
        if (is_array($stats) && isset($stats['size'])) {
148
        if (is_array($stats) && isset($stats['size'])) {
-
 
149
            $this->size = $stats['size'];
147
            $this->size = $stats['size'];
150
 
148
            return $this->size;
151
            return $this->size;
Línea 149... Línea 152...
149
        }
152
        }
150
 
153
 
Línea 205... Línea 208...
205
        if (!$this->seekable) {
208
        if (!$this->seekable) {
206
            throw new \RuntimeException('Stream is not seekable');
209
            throw new \RuntimeException('Stream is not seekable');
207
        }
210
        }
208
        if (fseek($this->stream, $offset, $whence) === -1) {
211
        if (fseek($this->stream, $offset, $whence) === -1) {
209
            throw new \RuntimeException('Unable to seek to stream position '
212
            throw new \RuntimeException('Unable to seek to stream position '
210
                . $offset . ' with whence ' . var_export($whence, true));
213
                .$offset.' with whence '.var_export($whence, true));
211
        }
214
        }
212
    }
215
    }
Línea 213... Línea 216...
213
 
216
 
214
    public function read($length): string
217
    public function read($length): string
Línea 259... Línea 262...
259
 
262
 
260
        return $result;
263
        return $result;
Línea 261... Línea 264...
261
    }
264
    }
262
 
-
 
263
    /**
-
 
264
     * {@inheritdoc}
265
 
265
     *
266
    /**
266
     * @return mixed
267
     * @return mixed
267
     */
268
     */
268
    public function getMetadata($key = null)
269
    public function getMetadata($key = null)