Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
namespace Laravel\SerializableClosure\Support;
4
 
5
#[\AllowDynamicProperties]
6
class ClosureStream
7
{
8
    /**
9
     * The stream protocol.
1441 ariadna 10
     *
11
     * @var string
1 efrain 12
     */
13
    const STREAM_PROTO = 'laravel-serializable-closure';
14
 
15
    /**
16
     * Checks if this stream is registered.
17
     *
18
     * @var bool
19
     */
20
    protected static $isRegistered = false;
21
 
22
    /**
23
     * The stream content.
24
     *
25
     * @var string
26
     */
27
    protected $content;
28
 
29
    /**
30
     * The stream content.
31
     *
32
     * @var int
33
     */
34
    protected $length;
35
 
36
    /**
37
     * The stream pointer.
38
     *
39
     * @var int
40
     */
41
    protected $pointer = 0;
42
 
43
    /**
44
     * Opens file or URL.
45
     *
46
     * @param  string  $path
47
     * @param  string  $mode
48
     * @param  string  $options
49
     * @param  string|null  $opened_path
50
     * @return bool
51
     */
52
    public function stream_open($path, $mode, $options, &$opened_path)
53
    {
54
        $this->content = "<?php\nreturn ".substr($path, strlen(static::STREAM_PROTO.'://')).';';
55
        $this->length = strlen($this->content);
56
 
57
        return true;
58
    }
59
 
60
    /**
61
     * Read from stream.
62
     *
63
     * @param  int  $count
64
     * @return string
65
     */
66
    public function stream_read($count)
67
    {
68
        $value = substr($this->content, $this->pointer, $count);
69
 
70
        $this->pointer += $count;
71
 
72
        return $value;
73
    }
74
 
75
    /**
76
     * Tests for end-of-file on a file pointer.
77
     *
78
     * @return bool
79
     */
80
    public function stream_eof()
81
    {
82
        return $this->pointer >= $this->length;
83
    }
84
 
85
    /**
86
     * Change stream options.
87
     *
88
     * @param  int  $option
89
     * @param  int  $arg1
90
     * @param  int  $arg2
91
     * @return bool
92
     */
93
    public function stream_set_option($option, $arg1, $arg2)
94
    {
95
        return false;
96
    }
97
 
98
    /**
99
     * Retrieve information about a file resource.
100
     *
101
     * @return array|bool
102
     */
103
    public function stream_stat()
104
    {
105
        $stat = stat(__FILE__);
106
        // @phpstan-ignore-next-line
107
        $stat[7] = $stat['size'] = $this->length;
108
 
109
        return $stat;
110
    }
111
 
112
    /**
113
     * Retrieve information about a file.
114
     *
115
     * @param  string  $path
116
     * @param  int  $flags
117
     * @return array|bool
118
     */
119
    public function url_stat($path, $flags)
120
    {
121
        $stat = stat(__FILE__);
122
        // @phpstan-ignore-next-line
123
        $stat[7] = $stat['size'] = $this->length;
124
 
125
        return $stat;
126
    }
127
 
128
    /**
129
     * Seeks to specific location in a stream.
130
     *
131
     * @param  int  $offset
132
     * @param  int  $whence
133
     * @return bool
134
     */
135
    public function stream_seek($offset, $whence = SEEK_SET)
136
    {
137
        $crt = $this->pointer;
138
 
139
        switch ($whence) {
140
            case SEEK_SET:
141
                $this->pointer = $offset;
142
                break;
143
            case SEEK_CUR:
144
                $this->pointer += $offset;
145
                break;
146
            case SEEK_END:
147
                $this->pointer = $this->length + $offset;
148
                break;
149
        }
150
 
151
        if ($this->pointer < 0 || $this->pointer >= $this->length) {
152
            $this->pointer = $crt;
153
 
154
            return false;
155
        }
156
 
157
        return true;
158
    }
159
 
160
    /**
161
     * Retrieve the current position of a stream.
162
     *
163
     * @return int
164
     */
165
    public function stream_tell()
166
    {
167
        return $this->pointer;
168
    }
169
 
170
    /**
171
     * Registers the stream.
172
     *
173
     * @return void
174
     */
175
    public static function register()
176
    {
177
        if (! static::$isRegistered) {
178
            static::$isRegistered = stream_wrapper_register(static::STREAM_PROTO, __CLASS__);
179
        }
180
    }
181
}