1 | <?php |
||
5 | class Filesystem |
||
6 | { |
||
7 | private $app; |
||
8 | protected $root; |
||
9 | protected $namespace; |
||
10 | |||
11 | 11 | public function __construct(Application $app, $root) |
|
16 | |||
17 | 1 | public function exists(string $path) : bool |
|
|
|||
18 | { |
||
19 | 1 | $path = call_user_func_array([$this, 'getPath'], func_get_args()); |
|
20 | 1 | return is_dir($path) || file_exists($path); |
|
21 | } |
||
22 | |||
23 | 11 | public function getPath(string $path = null) : string |
|
24 | { |
||
25 | 11 | if (func_get_args()) { |
|
26 | 11 | $chain = func_get_args(); |
|
27 | 11 | array_unshift($chain, $this->root); |
|
28 | 11 | foreach ($chain as $k => $v) { |
|
29 | 11 | if (!strlen($v)) { |
|
30 | 11 | unset($chain[$k]); |
|
31 | } |
||
32 | } |
||
33 | 11 | return implode(DIRECTORY_SEPARATOR, array_values($chain)); |
|
34 | } |
||
35 | |||
36 | 11 | return $this->root; |
|
37 | } |
||
38 | |||
39 | 11 | public function listClasses(string $namespace = '', string $location = 'php') : array |
|
61 | |||
62 | 11 | public function listFiles(string $location) : array |
|
63 | { |
||
64 | 11 | $absolute = $this->getPath($location); |
|
65 | 11 | if (!is_dir($absolute)) { |
|
66 | return []; |
||
67 | } |
||
68 | |||
69 | 11 | $result = []; |
|
70 | 11 | $relative = substr($absolute, strlen($this->getPath())); |
|
71 | 11 | foreach (scandir($absolute) as $file) { |
|
72 | 11 | if ($file != '.' && $file != '..') { |
|
73 | 11 | if (is_file("$absolute/$file")) { |
|
74 | 11 | $result[] = $file; |
|
75 | } else { |
||
76 | 6 | foreach ($this->listFiles("$relative/$file") as $child) { |
|
77 | 11 | $result[] = "$file/$child"; |
|
78 | } |
||
79 | } |
||
80 | } |
||
81 | } |
||
82 | |||
83 | 11 | return $result; |
|
84 | } |
||
85 | |||
86 | 11 | public function completeClassName(string $classname) : string |
|
93 | } |
||
94 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.