1 | <?php |
||
15 | class PathChecker |
||
16 | { |
||
17 | private static $include_paths = []; |
||
18 | private static $exclude_paths = []; |
||
19 | |||
20 | /** |
||
21 | * @param array $paths directory or file path |
||
22 | * @return array |
||
23 | * @throws RuntimeException |
||
24 | */ |
||
25 | protected static function normalizePaths(array $paths) |
||
26 | { |
||
27 | $new_paths = []; |
||
28 | $excluded = false; |
||
29 | foreach ($paths as $path) |
||
30 | { |
||
31 | // Path starting with '-' has special meaning (excluding it) |
||
32 | if (substr($path, 0, 1) === '-') |
||
33 | { |
||
34 | $excluded = true; |
||
35 | $path = ltrim($path, '-'); |
||
36 | } |
||
37 | |||
38 | $real_path = realpath($path); |
||
39 | if ($real_path === FALSE) |
||
40 | { |
||
41 | throw new RuntimeException($path . ' does not exist?'); |
||
42 | } |
||
43 | if (is_dir($real_path)) |
||
44 | { |
||
45 | // Must use DIRECTORY_SEPARATOR for Windows |
||
46 | $real_path = $real_path . DIRECTORY_SEPARATOR; |
||
47 | } |
||
48 | $new_paths[] = $excluded ? '-'.$real_path : $real_path; |
||
49 | } |
||
50 | array_unique($new_paths, SORT_STRING); |
||
51 | sort($new_paths, SORT_STRING); |
||
52 | return $new_paths; |
||
53 | } |
||
54 | |||
55 | public static function setIncludePaths(array $dir) |
||
59 | |||
60 | public static function setExcludePaths(array $dir) |
||
64 | |||
65 | public static function getIncludePaths() |
||
69 | |||
70 | public static function getExcludePaths() |
||
74 | |||
75 | public static function check($path) |
||
119 | } |
||
120 |