Analyzer.php
5 years ago
ClosureContext.php
5 years ago
ClosureScope.php
5 years ago
ClosureStream.php
5 years ago
ISecurityProvider.php
5 years ago
ReflectionClosure.php
5 years ago
SecurityException.php
5 years ago
SecurityProvider.php
5 years ago
SelfReference.php
5 years ago
SerializableClosure.php
5 years ago
ClosureStream.php
100 lines
| 1 | <?php |
| 2 | /* =========================================================================== |
| 3 | * Copyright (c) 2018-2019 Zindex Software |
| 4 | * |
| 5 | * Licensed under the MIT License |
| 6 | * =========================================================================== */ |
| 7 | |
| 8 | namespace Opis\Closure; |
| 9 | |
| 10 | /** |
| 11 | * @internal |
| 12 | */ |
| 13 | class ClosureStream |
| 14 | { |
| 15 | const STREAM_PROTO = 'closure'; |
| 16 | |
| 17 | protected static $isRegistered = false; |
| 18 | |
| 19 | protected $content; |
| 20 | |
| 21 | protected $length; |
| 22 | |
| 23 | protected $pointer = 0; |
| 24 | |
| 25 | function stream_open($path, $mode, $options, &$opened_path) |
| 26 | { |
| 27 | $this->content = "<?php\nreturn " . substr($path, strlen(static::STREAM_PROTO . '://')) . ";"; |
| 28 | $this->length = strlen($this->content); |
| 29 | return true; |
| 30 | } |
| 31 | |
| 32 | public function stream_read($count) |
| 33 | { |
| 34 | $value = substr($this->content, $this->pointer, $count); |
| 35 | $this->pointer += $count; |
| 36 | return $value; |
| 37 | } |
| 38 | |
| 39 | public function stream_eof() |
| 40 | { |
| 41 | return $this->pointer >= $this->length; |
| 42 | } |
| 43 | |
| 44 | public function stream_set_option($option, $arg1, $arg2) |
| 45 | { |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | public function stream_stat() |
| 50 | { |
| 51 | $stat = stat(__FILE__); |
| 52 | $stat[7] = $stat['size'] = $this->length; |
| 53 | return $stat; |
| 54 | } |
| 55 | |
| 56 | public function url_stat($path, $flags) |
| 57 | { |
| 58 | $stat = stat(__FILE__); |
| 59 | $stat[7] = $stat['size'] = $this->length; |
| 60 | return $stat; |
| 61 | } |
| 62 | |
| 63 | public function stream_seek($offset, $whence = SEEK_SET) |
| 64 | { |
| 65 | $crt = $this->pointer; |
| 66 | |
| 67 | switch ($whence) { |
| 68 | case SEEK_SET: |
| 69 | $this->pointer = $offset; |
| 70 | break; |
| 71 | case SEEK_CUR: |
| 72 | $this->pointer += $offset; |
| 73 | break; |
| 74 | case SEEK_END: |
| 75 | $this->pointer = $this->length + $offset; |
| 76 | break; |
| 77 | } |
| 78 | |
| 79 | if ($this->pointer < 0 || $this->pointer >= $this->length) { |
| 80 | $this->pointer = $crt; |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | return true; |
| 85 | } |
| 86 | |
| 87 | public function stream_tell() |
| 88 | { |
| 89 | return $this->pointer; |
| 90 | } |
| 91 | |
| 92 | public static function register() |
| 93 | { |
| 94 | if (!static::$isRegistered) { |
| 95 | static::$isRegistered = stream_wrapper_register(static::STREAM_PROTO, __CLASS__); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | } |
| 100 |