1 | <?php |
||
16 | class StreamReader |
||
17 | { |
||
18 | /** @var bool Flag whether allow_url_fopen is enabled */ |
||
19 | protected $isFopenEnabled = false; |
||
20 | |||
21 | /** @var string Data retrieved from remote */ |
||
22 | public $data = ''; |
||
23 | |||
24 | /** |
||
25 | * Constructor for fastImageSize class |
||
26 | */ |
||
27 | 72 | public function __construct() |
|
32 | |||
33 | /** |
||
34 | * Reset stream reader data |
||
35 | */ |
||
36 | 72 | public function resetData() |
|
40 | |||
41 | /** |
||
42 | * Get force length data |
||
43 | * |
||
44 | * @param int $offset |
||
45 | * @param int $length |
||
46 | * @return bool|string Returned data if long enough, false if not |
||
47 | */ |
||
48 | 47 | protected function getForcedLengthData($offset, $length) |
|
52 | |||
53 | /** |
||
54 | * Get image from specified path/source |
||
55 | * |
||
56 | * @param string $filename Path to image |
||
57 | * @param int $offset Offset at which reading of the image should start |
||
58 | * @param int $length Maximum length that should be read |
||
59 | * @param bool $forceLength True if the length needs to be the specified |
||
60 | * length, false if not. Default: true |
||
61 | * |
||
62 | * @return false|string Image data or false if result was empty |
||
63 | */ |
||
64 | 69 | public function getImage($filename, $offset, $length, $forceLength = true) |
|
80 | |||
81 | /** |
||
82 | * Get image data for specified filename with offset and length |
||
83 | * |
||
84 | * @param string $filename Path to image |
||
85 | * @param int $offset Offset at which reading of the image should start |
||
86 | * @param int $length Maximum length that should be read |
||
87 | */ |
||
88 | 69 | protected function getImageData($filename, $offset, $length) |
|
114 | |||
115 | /** |
||
116 | * Read data from guzzle request body |
||
117 | * |
||
118 | * @param \GuzzleHttp\Stream\StreamInterface $body Request body as stream |
||
119 | * @param int $length Requested length for file |
||
120 | * @return bool True while reading and not having reached the end of the |
||
121 | * targeted length, false if end of targeted length has been reached |
||
122 | */ |
||
123 | 1 | protected function readDataFromBody(\GuzzleHttp\Stream\StreamInterface $body, $length) |
|
134 | |||
135 | /** |
||
136 | * Get image data using file get contents if data is empty and |
||
137 | * allow_url_fopen is enabled |
||
138 | * |
||
139 | * @param string $filename Path to image |
||
140 | * @param int $offset Offset at which reading of the image should start |
||
141 | * @param int $length Maximum length that should be read |
||
142 | */ |
||
143 | 69 | protected function getImageDataFopen($filename, $offset, $length) |
|
150 | |||
151 | /** |
||
152 | * Get seekable image data in form of Guzzle stream interface |
||
153 | * |
||
154 | * @param string $filename Filename / URL to get |
||
155 | * @param int $offset Offset for response body |
||
156 | * @return \GuzzleHttp\Stream\StreamInterface|null Stream interface of |
||
157 | * requested image or null if it could not be retrieved |
||
158 | */ |
||
159 | 27 | public function getSeekableImageData($filename, $offset) |
|
174 | } |
||
175 |