@@ 266-312 (lines=47) @@ | ||
263 | * |
|
264 | * @throws \Robo\Exception\TaskException |
|
265 | */ |
|
266 | protected function findFiles($dirs) |
|
267 | { |
|
268 | $files = array(); |
|
269 | ||
270 | // find the files |
|
271 | foreach ($dirs as $k => $v) { |
|
272 | // reset finder |
|
273 | $finder = new Finder(); |
|
274 | ||
275 | $dir = $k; |
|
276 | $to = $v; |
|
277 | // check if target was given with the to() method instead of key/value pairs |
|
278 | if (is_int($k)) { |
|
279 | $dir = $v; |
|
280 | if (isset($this->to)) { |
|
281 | $to = $this->to; |
|
282 | } else { |
|
283 | throw new TaskException($this, 'target directory is not defined'); |
|
284 | } |
|
285 | } |
|
286 | ||
287 | try { |
|
288 | $finder->files()->in($dir); |
|
289 | } catch (\InvalidArgumentException $e) { |
|
290 | // if finder cannot handle it, try with in()->name() |
|
291 | if (strpos($dir, '/') === false) { |
|
292 | $dir = './'.$dir; |
|
293 | } |
|
294 | $parts = explode('/', $dir); |
|
295 | $new_dir = implode('/', array_slice($parts, 0, -1)); |
|
296 | try { |
|
297 | $finder->files()->in($new_dir)->name(array_pop($parts)); |
|
298 | } catch (\InvalidArgumentException $e) { |
|
299 | return Result::fromException($this, $e); |
|
300 | } |
|
301 | } |
|
302 | ||
303 | foreach ($finder as $file) { |
|
304 | // store the absolute path as key and target as value in the files array |
|
305 | $files[$file->getRealpath()] = $this->getTarget($file->getRealPath(), $to); |
|
306 | } |
|
307 | $fileNoun = count($finder) == 1 ? ' file' : ' files'; |
|
308 | $this->printTaskInfo("Found {filecount} $fileNoun in {dir}", ['filecount' => count($finder), 'dir' => $dir]); |
|
309 | } |
|
310 | ||
311 | return $files; |
|
312 | } |
|
313 | ||
314 | /** |
|
315 | * @param string $file |
@@ 207-253 (lines=47) @@ | ||
204 | * |
|
205 | * @throws \Robo\Exception\TaskException |
|
206 | */ |
|
207 | protected function findFiles($dirs) |
|
208 | { |
|
209 | $files = array(); |
|
210 | ||
211 | // find the files |
|
212 | foreach ($dirs as $k => $v) { |
|
213 | // reset finder |
|
214 | $finder = new Finder(); |
|
215 | ||
216 | $dir = $k; |
|
217 | $to = $v; |
|
218 | // check if target was given with the to() method instead of key/value pairs |
|
219 | if (is_int($k)) { |
|
220 | $dir = $v; |
|
221 | if (isset($this->to)) { |
|
222 | $to = $this->to; |
|
223 | } else { |
|
224 | throw new TaskException($this, 'target directory is not defined'); |
|
225 | } |
|
226 | } |
|
227 | ||
228 | try { |
|
229 | $finder->files()->in($dir); |
|
230 | } catch (\InvalidArgumentException $e) { |
|
231 | // if finder cannot handle it, try with in()->name() |
|
232 | if (strpos($dir, '/') === false) { |
|
233 | $dir = './'.$dir; |
|
234 | } |
|
235 | $parts = explode('/', $dir); |
|
236 | $new_dir = implode('/', array_slice($parts, 0, -1)); |
|
237 | try { |
|
238 | $finder->files()->in($new_dir)->name(array_pop($parts)); |
|
239 | } catch (\InvalidArgumentException $e) { |
|
240 | return Result::fromException($this, $e); |
|
241 | } |
|
242 | } |
|
243 | ||
244 | foreach ($finder as $file) { |
|
245 | // store the absolute path as key and target as value in the files array |
|
246 | $files[$file->getRealpath()] = $this->getTarget($file->getRealPath(), $to); |
|
247 | } |
|
248 | $fileNoun = count($files) == 1 ? ' file' : ' files'; |
|
249 | $this->printTaskInfo("Found {count} $fileNoun in {dir}", ['count' => count($files), 'dir' => $dir]); |
|
250 | } |
|
251 | ||
252 | return $files; |
|
253 | } |
|
254 | ||
255 | /** |
|
256 | * @param string $file |