| @@ 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 |
|
| @@ 269-315 (lines=47) @@ | ||
| 266 | * |
|
| 267 | * @throws \Robo\Exception\TaskException |
|
| 268 | */ |
|
| 269 | protected function findFiles($dirs) |
|
| 270 | { |
|
| 271 | $files = array(); |
|
| 272 | ||
| 273 | // find the files |
|
| 274 | foreach ($dirs as $k => $v) { |
|
| 275 | // reset finder |
|
| 276 | $finder = new Finder(); |
|
| 277 | ||
| 278 | $dir = $k; |
|
| 279 | $to = $v; |
|
| 280 | // check if target was given with the to() method instead of key/value pairs |
|
| 281 | if (is_int($k)) { |
|
| 282 | $dir = $v; |
|
| 283 | if (isset($this->to)) { |
|
| 284 | $to = $this->to; |
|
| 285 | } else { |
|
| 286 | throw new TaskException($this, 'target directory is not defined'); |
|
| 287 | } |
|
| 288 | } |
|
| 289 | ||
| 290 | try { |
|
| 291 | $finder->files()->in($dir); |
|
| 292 | } catch (\InvalidArgumentException $e) { |
|
| 293 | // if finder cannot handle it, try with in()->name() |
|
| 294 | if (strpos($dir, '/') === false) { |
|
| 295 | $dir = './' . $dir; |
|
| 296 | } |
|
| 297 | $parts = explode('/', $dir); |
|
| 298 | $new_dir = implode('/', array_slice($parts, 0, -1)); |
|
| 299 | try { |
|
| 300 | $finder->files()->in($new_dir)->name(array_pop($parts)); |
|
| 301 | } catch (\InvalidArgumentException $e) { |
|
| 302 | return Result::fromException($this, $e); |
|
| 303 | } |
|
| 304 | } |
|
| 305 | ||
| 306 | foreach ($finder as $file) { |
|
| 307 | // store the absolute path as key and target as value in the files array |
|
| 308 | $files[$file->getRealpath()] = $this->getTarget($file->getRealPath(), $to); |
|
| 309 | } |
|
| 310 | $fileNoun = count($finder) == 1 ? ' file' : ' files'; |
|
| 311 | $this->printTaskInfo("Found {filecount} $fileNoun in {dir}", ['filecount' => count($finder), 'dir' => $dir]); |
|
| 312 | } |
|
| 313 | ||
| 314 | return $files; |
|
| 315 | } |
|
| 316 | ||
| 317 | /** |
|
| 318 | * @param string $file |
|