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