1 | <?php |
||
17 | class StreamHandler |
||
18 | { |
||
19 | private $globs = []; |
||
20 | |||
21 | private $toPush = []; |
||
22 | |||
23 | private $temp = []; |
||
24 | |||
25 | private $streams = []; |
||
26 | |||
27 | /** |
||
28 | * Provides streams by the pattern passed |
||
29 | * |
||
30 | * @param string|array $accept |
||
31 | * @param string|array|null $exclude |
||
32 | * |
||
33 | * @return self |
||
34 | */ |
||
35 | public function src($accept, $exclude = null) : self |
||
61 | |||
62 | /** |
||
63 | * Handle each stream |
||
64 | * |
||
65 | * @param callable|PluginInterface $callback |
||
66 | * |
||
67 | * @return self |
||
68 | */ |
||
69 | public function forStream($callback) : self |
||
87 | |||
88 | /** |
||
89 | * Handle all streams |
||
90 | * |
||
91 | * @param callable|PluginInterface $callback |
||
92 | * |
||
93 | * @return self |
||
94 | */ |
||
95 | public function forStreams($callback) : self |
||
109 | |||
110 | private function getCallback($cb) : callable |
||
122 | |||
123 | /** |
||
124 | * Pushes a stream to be used on destination |
||
125 | * |
||
126 | * @param StreamInterface $stream |
||
127 | */ |
||
128 | public function push(StreamInterface $stream) |
||
132 | |||
133 | /** |
||
134 | * Creates a temporary stream |
||
135 | * It will be deleted in the end of task execution |
||
136 | * |
||
137 | * @param StreamInterface $stream |
||
138 | */ |
||
139 | public function temp(StreamInterface $stream) |
||
144 | |||
145 | /** |
||
146 | * Sends pushed streams to a directory (plugin) |
||
147 | * |
||
148 | * @param string $dest |
||
149 | * |
||
150 | * @return callable |
||
151 | */ |
||
152 | public function toDir(string $dest) : ToDirPlugin |
||
156 | |||
157 | /** |
||
158 | * Cleans up pushed streams and delete indicated temporary files |
||
159 | * |
||
160 | * @return self |
||
161 | */ |
||
162 | public function end() : self |
||
173 | |||
174 | /** |
||
175 | * Destructor closes all opened streams |
||
176 | */ |
||
177 | public function __destruct() |
||
181 | |||
182 | private function recoursiveGlob($pattern, $flags = 0) : array |
||
218 | |||
219 | /** |
||
220 | * Ignore files provided by glob function |
||
221 | * |
||
222 | * @param array $files |
||
223 | * @param array|string|null $patterns |
||
224 | * |
||
225 | * @return array |
||
226 | */ |
||
227 | private function ignoreFiles(array $files, $patterns) |
||
253 | |||
254 | /** |
||
255 | * Closes all opened streams |
||
256 | */ |
||
257 | private function closeAll() |
||
267 | } |