Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 16... Línea 16...
16
 * the read() function of the PumpStream. The provided callable MUST return
16
 * the read() function of the PumpStream. The provided callable MUST return
17
 * false when there is no more data to read.
17
 * false when there is no more data to read.
18
 */
18
 */
19
final class PumpStream implements StreamInterface
19
final class PumpStream implements StreamInterface
20
{
20
{
21
    /** @var callable|null */
21
    /** @var callable(int): (string|false|null)|null */
22
    private $source;
22
    private $source;
Línea 23... Línea 23...
23
 
23
 
24
    /** @var int|null */
24
    /** @var int|null */
Línea 32... Línea 32...
32
 
32
 
33
    /** @var BufferStream */
33
    /** @var BufferStream */
Línea 34... Línea 34...
34
    private $buffer;
34
    private $buffer;
35
 
35
 
36
    /**
36
    /**
37
     * @param callable(int): (string|null|false)  $source  Source of the stream data. The callable MAY
37
     * @param callable(int): (string|false|null)  $source  Source of the stream data. The callable MAY
38
     *                                                     accept an integer argument used to control the
38
     *                                                     accept an integer argument used to control the
39
     *                                                     amount of data to return. The callable MUST
39
     *                                                     amount of data to return. The callable MUST
40
     *                                                     return a string when called, or false|null on error
40
     *                                                     return a string when called, or false|null on error
Línea 58... Línea 58...
58
        } catch (\Throwable $e) {
58
        } catch (\Throwable $e) {
59
            if (\PHP_VERSION_ID >= 70400) {
59
            if (\PHP_VERSION_ID >= 70400) {
60
                throw $e;
60
                throw $e;
61
            }
61
            }
62
            trigger_error(sprintf('%s::__toString exception: %s', self::class, (string) $e), E_USER_ERROR);
62
            trigger_error(sprintf('%s::__toString exception: %s', self::class, (string) $e), E_USER_ERROR);
-
 
63
 
63
            return '';
64
            return '';
64
        }
65
        }
65
    }
66
    }
Línea 66... Línea 67...
66
 
67
 
Línea 147... Línea 148...
147
 
148
 
148
        return $result;
149
        return $result;
Línea 149... Línea 150...
149
    }
150
    }
150
 
-
 
151
    /**
-
 
152
     * {@inheritdoc}
151
 
153
     *
152
    /**
154
     * @return mixed
153
     * @return mixed
155
     */
154
     */
156
    public function getMetadata($key = null)
155
    public function getMetadata($key = null)
Línea 162... Línea 161...
162
        return $this->metadata[$key] ?? null;
161
        return $this->metadata[$key] ?? null;
163
    }
162
    }
Línea 164... Línea 163...
164
 
163
 
165
    private function pump(int $length): void
164
    private function pump(int $length): void
166
    {
165
    {
167
        if ($this->source) {
166
        if ($this->source !== null) {
168
            do {
167
            do {
169
                $data = call_user_func($this->source, $length);
168
                $data = ($this->source)($length);
170
                if ($data === false || $data === null) {
169
                if ($data === false || $data === null) {
-
 
170
                    $this->source = null;
171
                    $this->source = null;
171
 
172
                    return;
172
                    return;
173
                }
173
                }
174
                $this->buffer->write($data);
174
                $this->buffer->write($data);
175
                $length -= strlen($data);
175
                $length -= strlen($data);