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
final class FnStream implements StreamInterface
16
final class FnStream implements StreamInterface
17
{
17
{
18
    private const SLOTS = [
18
    private const SLOTS = [
19
        '__toString', 'close', 'detach', 'rewind',
19
        '__toString', 'close', 'detach', 'rewind',
20
        'getSize', 'tell', 'eof', 'isSeekable', 'seek', 'isWritable', 'write',
20
        'getSize', 'tell', 'eof', 'isSeekable', 'seek', 'isWritable', 'write',
21
        'isReadable', 'read', 'getContents', 'getMetadata'
21
        'isReadable', 'read', 'getContents', 'getMetadata',
22
    ];
22
    ];
Línea 23... Línea 23...
23
 
23
 
24
    /** @var array<string, callable> */
24
    /** @var array<string, callable> */
Línea 31... Línea 31...
31
    {
31
    {
32
        $this->methods = $methods;
32
        $this->methods = $methods;
Línea 33... Línea 33...
33
 
33
 
34
        // Create the functions on the class
34
        // Create the functions on the class
35
        foreach ($methods as $name => $fn) {
35
        foreach ($methods as $name => $fn) {
36
            $this->{'_fn_' . $name} = $fn;
36
            $this->{'_fn_'.$name} = $fn;
37
        }
37
        }
Línea 38... Línea 38...
38
    }
38
    }
39
 
39
 
Línea 43... Línea 43...
43
     * @throws \BadMethodCallException
43
     * @throws \BadMethodCallException
44
     */
44
     */
45
    public function __get(string $name): void
45
    public function __get(string $name): void
46
    {
46
    {
47
        throw new \BadMethodCallException(str_replace('_fn_', '', $name)
47
        throw new \BadMethodCallException(str_replace('_fn_', '', $name)
48
            . '() is not implemented in the FnStream');
48
            .'() is not implemented in the FnStream');
49
    }
49
    }
Línea 50... Línea 50...
50
 
50
 
51
    /**
51
    /**
52
     * The close method is called on the underlying stream only if possible.
52
     * The close method is called on the underlying stream only if possible.
53
     */
53
     */
54
    public function __destruct()
54
    public function __destruct()
55
    {
55
    {
56
        if (isset($this->_fn_close)) {
56
        if (isset($this->_fn_close)) {
57
            call_user_func($this->_fn_close);
57
            ($this->_fn_close)();
58
        }
58
        }
Línea 59... Línea 59...
59
    }
59
    }
60
 
60
 
Línea 91... Línea 91...
91
    }
91
    }
Línea 92... Línea 92...
92
 
92
 
93
    public function __toString(): string
93
    public function __toString(): string
94
    {
94
    {
-
 
95
        try {
95
        try {
96
            /** @var string */
96
            return call_user_func($this->_fn___toString);
97
            return ($this->_fn___toString)();
97
        } catch (\Throwable $e) {
98
        } catch (\Throwable $e) {
98
            if (\PHP_VERSION_ID >= 70400) {
99
            if (\PHP_VERSION_ID >= 70400) {
99
                throw $e;
100
                throw $e;
100
            }
101
            }
-
 
102
            trigger_error(sprintf('%s::__toString exception: %s', self::class, (string) $e), E_USER_ERROR);
101
            trigger_error(sprintf('%s::__toString exception: %s', self::class, (string) $e), E_USER_ERROR);
103
 
102
            return '';
104
            return '';
103
        }
105
        }
Línea 104... Línea 106...
104
    }
106
    }
105
 
107
 
106
    public function close(): void
108
    public function close(): void
107
    {
109
    {
Línea 108... Línea 110...
108
        call_user_func($this->_fn_close);
110
        ($this->_fn_close)();
109
    }
111
    }
110
 
112
 
111
    public function detach()
113
    public function detach()
Línea 112... Línea 114...
112
    {
114
    {
113
        return call_user_func($this->_fn_detach);
115
        return ($this->_fn_detach)();
114
    }
116
    }
115
 
117
 
Línea 116... Línea 118...
116
    public function getSize(): ?int
118
    public function getSize(): ?int
117
    {
119
    {
118
        return call_user_func($this->_fn_getSize);
120
        return ($this->_fn_getSize)();
119
    }
121
    }
Línea 120... Línea 122...
120
 
122
 
121
    public function tell(): int
123
    public function tell(): int
122
    {
124
    {
123
        return call_user_func($this->_fn_tell);
125
        return ($this->_fn_tell)();
Línea 124... Línea 126...
124
    }
126
    }
125
 
127
 
126
    public function eof(): bool
128
    public function eof(): bool
127
    {
129
    {
Línea 128... Línea 130...
128
        return call_user_func($this->_fn_eof);
130
        return ($this->_fn_eof)();
129
    }
131
    }
130
 
132
 
131
    public function isSeekable(): bool
133
    public function isSeekable(): bool
Línea 132... Línea 134...
132
    {
134
    {
133
        return call_user_func($this->_fn_isSeekable);
135
        return ($this->_fn_isSeekable)();
134
    }
136
    }
135
 
137
 
Línea 136... Línea 138...
136
    public function rewind(): void
138
    public function rewind(): void
137
    {
139
    {
138
        call_user_func($this->_fn_rewind);
140
        ($this->_fn_rewind)();
139
    }
141
    }
Línea 140... Línea 142...
140
 
142
 
141
    public function seek($offset, $whence = SEEK_SET): void
143
    public function seek($offset, $whence = SEEK_SET): void
142
    {
144
    {
143
        call_user_func($this->_fn_seek, $offset, $whence);
145
        ($this->_fn_seek)($offset, $whence);
Línea 144... Línea 146...
144
    }
146
    }
145
 
147
 
146
    public function isWritable(): bool
148
    public function isWritable(): bool
147
    {
149
    {
Línea 148... Línea 150...
148
        return call_user_func($this->_fn_isWritable);
150
        return ($this->_fn_isWritable)();
149
    }
151
    }
150
 
152
 
151
    public function write($string): int
153
    public function write($string): int
Línea 152... Línea 154...
152
    {
154
    {
153
        return call_user_func($this->_fn_write, $string);
155
        return ($this->_fn_write)($string);
154
    }
156
    }
155
 
157
 
Línea 156... Línea 158...
156
    public function isReadable(): bool
158
    public function isReadable(): bool
157
    {
-
 
158
        return call_user_func($this->_fn_isReadable);
-
 
159
    }
159
    {
160
 
160
        return ($this->_fn_isReadable)();
161
    public function read($length): string
161
    }
162
    {
162
 
163
        return call_user_func($this->_fn_read, $length);
163
    public function read($length): string
164
    }
164
    {
165
 
165
        return ($this->_fn_read)($length);