1 | <?php |
||
9 | class LaravelEnvScanner |
||
10 | { |
||
11 | /** |
||
12 | * The results of performed scan |
||
13 | * |
||
14 | * @var array |
||
15 | */ |
||
16 | public $results = [ |
||
17 | 'files' => 0, |
||
18 | 'defined' => 0, |
||
19 | 'undefined' => 0, |
||
20 | 'depending_on_default' => 0, |
||
21 | 'columns' => [], |
||
22 | ]; |
||
23 | |||
24 | /** |
||
25 | * Stores processed file and var names |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | private $processed = [ |
||
30 | 'files' => [], |
||
31 | 'vars' => [], |
||
32 | ]; |
||
33 | |||
34 | /** |
||
35 | * Stores undefined var names |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | public $undefined = []; |
||
40 | |||
41 | /** |
||
42 | * Stores warnings for vars not passing validation |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | public $warnings = []; |
||
47 | |||
48 | /** |
||
49 | * Current file being processed |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | private $currentFile; |
||
54 | |||
55 | /** |
||
56 | * Root directory to start recursive search for env()'s from |
||
57 | * Defaults to config_path() |
||
58 | * |
||
59 | * @var string $dir |
||
60 | */ |
||
61 | public $dir; |
||
62 | |||
63 | public function __construct(string $dir = null) |
||
67 | |||
68 | /** |
||
69 | * Run the scan |
||
70 | * |
||
71 | * @return mixed |
||
72 | * @throws \Exception |
||
73 | */ |
||
74 | public function scan() |
||
108 | |||
109 | /** |
||
110 | * Get result based on comma separated parsed env() or getenv() parameters |
||
111 | * Validates by alphanumeric and underscore and skips already processed |
||
112 | * |
||
113 | * @param string $invocation |
||
114 | * @param array $matches |
||
115 | * @return object|bool |
||
116 | */ |
||
117 | private function getResult(string $invocation, array $matches) |
||
148 | |||
149 | /** |
||
150 | * Store result and optional runtime output |
||
151 | * |
||
152 | * @param $result |
||
153 | */ |
||
154 | private function storeResult($result) |
||
181 | |||
182 | /** |
||
183 | * Return filename or '-' for table |
||
184 | * |
||
185 | * @return string |
||
186 | */ |
||
187 | private function getColumnFilename(): string |
||
195 | |||
196 | private function recursiveDirSearch(string $folder, string $pattern): array |
||
217 | } |
||
218 |