-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinderFacade.php
71 lines (55 loc) · 1.49 KB
/
FinderFacade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
declare(strict_types=1);
namespace Scheb\Tombstone\Core;
use Symfony\Component\Finder\Finder;
class FinderFacade
{
private $items = [];
private $excludes = [];
private $names = [];
private $notNames = [];
public function __construct(array $items = [], array $excludes = [], array $names = [], array $notNames = [])
{
$this->items = $items;
$this->excludes = $excludes;
$this->names = $names;
$this->notNames = $notNames;
}
/**
* @psalm-suppress InvalidReturnType
* @psalm-suppress InvalidReturnStatement
*
* @return string[]
*/
public function findFiles(): array
{
$files = [];
$finder = new Finder();
$iterate = false;
$finder->ignoreUnreadableDirs();
$finder->sortByName();
foreach ($this->items as $item) {
if (!is_file($item)) {
$finder->in($item);
$iterate = true;
} else {
$files[] = realpath($item);
}
}
foreach ($this->excludes as $exclude) {
$finder->exclude($exclude);
}
foreach ($this->names as $name) {
$finder->name($name);
}
foreach ($this->notNames as $notName) {
$finder->notName($notName);
}
if ($iterate) {
foreach ($finder as $file) {
$files[] = $file->getRealpath();
}
}
return $files;
}
}