1 | <?php |
||
17 | abstract class ClassDiscovery |
||
18 | { |
||
19 | /** |
||
20 | * A list of strategies to find classes. |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | private static $strategies = [ |
||
25 | Strategy\PuliBetaStrategy::class, |
||
26 | Strategy\CommonClassesStrategy::class, |
||
27 | Strategy\CommonPsr17ClassesStrategy::class, |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * Discovery cache to make the second time we use discovery faster. |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | private static $cache = []; |
||
36 | |||
37 | /** |
||
38 | * Finds a class. |
||
39 | * |
||
40 | * @param string $type |
||
41 | * |
||
42 | * @return string|\Closure |
||
43 | * |
||
44 | * @throws DiscoveryFailedException |
||
45 | */ |
||
46 | 15 | protected static function findOneByType($type) |
|
81 | |||
82 | /** |
||
83 | * Get a value from cache. |
||
84 | * |
||
85 | * @param string $type |
||
86 | * |
||
87 | * @return string|null |
||
88 | */ |
||
89 | 15 | private static function getFromCache($type) |
|
104 | |||
105 | /** |
||
106 | * Store a value in cache. |
||
107 | * |
||
108 | * @param string $type |
||
109 | * @param string $class |
||
110 | */ |
||
111 | 9 | private static function storeInCache($type, $class) |
|
115 | |||
116 | /** |
||
117 | * Set new strategies and clear the cache. |
||
118 | * |
||
119 | * @param array $strategies string array of fully qualified class name to a DiscoveryStrategy |
||
120 | */ |
||
121 | 28 | public static function setStrategies(array $strategies) |
|
126 | |||
127 | /** |
||
128 | * Returns the currently configured discovery strategies as fully qualified class names. |
||
129 | * |
||
130 | * @return string[] |
||
131 | */ |
||
132 | 1 | public static function getStrategies(): iterable |
|
136 | 1 | ||
137 | /** |
||
138 | * Append a strategy at the end of the strategy queue. |
||
139 | * |
||
140 | * @param string $strategy Fully qualified class name to a DiscoveryStrategy |
||
141 | */ |
||
142 | public static function appendStrategy($strategy) |
||
147 | 1 | ||
148 | /** |
||
149 | * Prepend a strategy at the beginning of the strategy queue. |
||
150 | * |
||
151 | * @param string $strategy Fully qualified class name to a DiscoveryStrategy |
||
152 | 28 | */ |
|
153 | public static function prependStrategy($strategy) |
||
158 | |||
159 | /** |
||
160 | * Clear the cache. |
||
161 | */ |
||
162 | public static function clearCache() |
||
166 | 7 | ||
167 | /** |
||
168 | * Evaluates conditions to boolean. |
||
169 | * |
||
170 | 7 | * @param mixed $condition |
|
171 | * |
||
172 | * @return bool |
||
173 | 7 | */ |
|
174 | 7 | protected static function evaluateCondition($condition) |
|
199 | 5 | ||
200 | /** |
||
201 | * Get an instance of the $class. |
||
202 | 5 | * |
|
203 | 5 | * @param string|\Closure $class A FQCN of a class or a closure that instantiate the class. |
|
204 | * |
||
205 | * @return object |
||
206 | * |
||
207 | * @throws ClassInstantiationFailedException |
||
208 | */ |
||
209 | protected static function instantiateClass($class) |
||
225 | |||
226 | /** |
||
227 | * We want to do a "safe" version of PHP's "class_exists" because Magento has a bug |
||
228 | * (or they call it a "feature"). Magento is throwing an exception if you do class_exists() |
||
229 | * on a class that ends with "Factory" and if that file does not exits. |
||
230 | * |
||
231 | * This function will catch all potential exceptions and make sure it returns a boolean. |
||
232 | * |
||
233 | * @param string $class |
||
234 | * @param bool $autoload |
||
|
|||
235 | * |
||
236 | * @return bool |
||
237 | */ |
||
238 | public static function safeClassExists($class) |
||
246 | } |
||
247 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.