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 | /** |
||
111 | * Pushes a stream to be used on destination |
||
112 | * |
||
113 | * @param StreamInterface $stream |
||
114 | */ |
||
115 | public function push(StreamInterface $stream) |
||
119 | |||
120 | /** |
||
121 | * Creates a temporary stream |
||
122 | * It will be deleted in the end of task execution |
||
123 | * |
||
124 | * @param StreamInterface $stream |
||
125 | */ |
||
126 | public function temp(StreamInterface $stream) |
||
131 | |||
132 | /** |
||
133 | * Sends pushed streams to a directory (plugin) |
||
134 | * |
||
135 | * @param string $dest |
||
136 | * |
||
137 | * @return callable |
||
138 | */ |
||
139 | public function toDir(string $dest) : ToDirPlugin |
||
143 | |||
144 | /** |
||
145 | * Cleans up pushed streams and delete indicated temporary files |
||
146 | * |
||
147 | * @return self |
||
148 | */ |
||
149 | public function end() : self |
||
160 | |||
161 | /** |
||
162 | * Destructor closes all opened streams |
||
163 | */ |
||
164 | public function __destruct() |
||
168 | |||
169 | /** |
||
170 | * Search for files inside folders and subfolders |
||
171 | * |
||
172 | * @param string $pattern |
||
173 | * @param integer $flags |
||
174 | * |
||
175 | * @return array |
||
176 | */ |
||
177 | private function recoursiveGlob($pattern, $flags = 0) : array |
||
213 | |||
214 | /** |
||
215 | * Ignore files provided by glob function |
||
216 | * |
||
217 | * @param array $files |
||
218 | * @param array|string|null $patterns |
||
219 | * |
||
220 | * @return array |
||
221 | */ |
||
222 | private function ignoreFiles(array $files, $patterns) |
||
248 | |||
249 | /** |
||
250 | * Returns a plugin callback |
||
251 | * |
||
252 | * @param PluginInterface|callable $cb |
||
253 | * |
||
254 | * @return callable |
||
255 | */ |
||
256 | private function getCallback($cb) : callable |
||
268 | |||
269 | /** |
||
270 | * Closes all opened streams |
||
271 | */ |
||
272 | private function closeAll() |
||
282 | } |