1 | <?php |
||
11 | class ClassFinder |
||
12 | { |
||
13 | /** @var string[] List of file extensions used to find files */ |
||
14 | private $fileExtensions; |
||
15 | |||
16 | /** |
||
17 | * Creates a new PathFinder instance. |
||
18 | */ |
||
19 | 96 | public function __construct() |
|
23 | |||
24 | /** |
||
25 | * Sets list of dot included file extensions to use for finding files. |
||
26 | * |
||
27 | * If no list of extensions is provided, the extension array defaults to |
||
28 | * just '.php'. |
||
29 | * |
||
30 | * @param string[] $extensions Array of dot included file extensions to use |
||
31 | */ |
||
32 | 3 | public function setFileExtensions(array $extensions) |
|
36 | |||
37 | /** |
||
38 | * Attempts to find a file for the given class from given paths. |
||
39 | * |
||
40 | * Both lists of paths must be given as arrays with keys indicating the |
||
41 | * namespace. Empty string can be used for the paths that apply to all |
||
42 | * Classes. Each value must be an array of paths. |
||
43 | * |
||
44 | * @param string $class Full name of the class |
||
45 | * @param array $prefixPaths List of paths used for PSR-4 file search |
||
46 | * @param array $basePaths List of paths used for PSR-0 file search |
||
47 | * @param bool $useIncludePath Whether to use paths in include_path for PSR-0 search or not |
||
48 | * @return string|false Path to the class file or false if not found |
||
49 | */ |
||
50 | 60 | public function findFile($class, array $prefixPaths, array $basePaths = [], $useIncludePath = false) |
|
66 | |||
67 | /** |
||
68 | * Searches for the class file from the namespaces that apply to the class. |
||
69 | * @param array $paths All the namespace specific paths |
||
70 | * @param string $class Canonized full class name |
||
71 | * @param bool $truncate True to remove the namespace from the path |
||
72 | * @return string|false Path to the class file or false if not found |
||
73 | */ |
||
74 | 60 | private function searchNamespaces($paths, $class, $truncate) |
|
86 | |||
87 | /** |
||
88 | * Matches the class against the namespace and canonizes the name as needed. |
||
89 | * @param string $namespace Namespace to match against |
||
90 | * @param string $class Full name of the class |
||
91 | * @param bool $truncate Whether to remove the namespace from the class |
||
92 | * @return string|false Canonized class name or false if it does not match the namespace |
||
93 | */ |
||
94 | 48 | private function canonizeClass($namespace, $class, $truncate) |
|
107 | |||
108 | /** |
||
109 | * Searches for the class file in the list of directories. |
||
110 | * @param string[] $directories List of directory paths where to look for the class |
||
111 | * @param string $class Part of the class name that translates to the file name |
||
112 | * @return string|false Path to the class file or false if not found |
||
113 | */ |
||
114 | 51 | private function searchDirectories(array $directories, $class) |
|
127 | |||
128 | /** |
||
129 | * Searches for the class file using known file extensions. |
||
130 | * @param string $path Path to the class file without the file extension |
||
131 | * @return string|false Path to the class file or false if not found |
||
132 | */ |
||
133 | 48 | private function searchExtensions($path) |
|
143 | } |
||
144 |