1 | <?php |
||
15 | class Resolver |
||
16 | { |
||
17 | /** |
||
18 | * Instance of composer, since this will be used to load the ps4 prefixes |
||
19 | * |
||
20 | * @var ClassLoader |
||
21 | */ |
||
22 | private $composer; |
||
23 | |||
24 | /** |
||
25 | * Resolver constructor. |
||
26 | * |
||
27 | * @param ClassLoader $composer |
||
28 | */ |
||
29 | public function __construct(ClassLoader $composer) |
||
33 | |||
34 | /** |
||
35 | * Find all of the avaiable classes under a specific namespace |
||
36 | * |
||
37 | * @param string $namespace The namespace to search for |
||
38 | * @param string $instanceOf optional, restrict the classes found to those |
||
39 | * that extend from this base |
||
40 | * @return array a list of FQCN's that match |
||
41 | */ |
||
42 | public function findClasses(string $namespace, string $instanceOf = null): array |
||
70 | |||
71 | /** |
||
72 | * Resolve a psr4 based namespace to an absolute directory |
||
73 | * |
||
74 | * @param string $namespace |
||
75 | * @return array |
||
76 | * @throws Exception |
||
77 | */ |
||
78 | public function resolveDirectory(string $namespace): array |
||
98 | |||
99 | /** |
||
100 | * Find the best psr4 namespace prefix, based on the supplied namespace, and |
||
101 | * list of provided prefix |
||
102 | * |
||
103 | * @param string $namespace |
||
104 | * @param array $prefixes |
||
105 | * @return string |
||
106 | */ |
||
107 | private function findPrefix(string $namespace, array $prefixes): string |
||
122 | |||
123 | /** |
||
124 | * Convert the supplied namespace string into a standard format |
||
125 | * no prefix, ends with trailing slash |
||
126 | * |
||
127 | * Example: |
||
128 | * Psr4\Prefix\ |
||
129 | * Something\ |
||
130 | * |
||
131 | * @param string $namespace |
||
132 | * @return string |
||
133 | * @throws Exception |
||
134 | */ |
||
135 | private function normalise(string $namespace): string |
||
144 | |||
145 | /** |
||
146 | * Get an absolute path for the provided namespace, based on a existing |
||
147 | * directory and its psr4 prefix |
||
148 | * |
||
149 | * @param string $namespace |
||
150 | * @param string $psr4Prefix the psr4 prefix |
||
151 | * @param string $psr4Path and it's related path |
||
152 | * @return string the absolute directory path the provided namespace, given |
||
153 | * the correct prefix and path empty string if path can't |
||
154 | * be resolved |
||
155 | */ |
||
156 | private function findAbsolutePathForPsr4(string $namespace, string $psr4Prefix, string $psr4Path): string |
||
170 | |||
171 | |||
172 | /** |
||
173 | * Retrieve a directory iterator for the supplied path |
||
174 | * |
||
175 | * @param string $path The directory to iterate |
||
176 | * @return \RegexIterator |
||
177 | */ |
||
178 | private function getDirectoryIterator(string $path): \RegexIterator |
||
184 | } |
||
185 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: