1 | <?php |
||
16 | abstract class ClassDiscovery |
||
17 | { |
||
18 | /** |
||
19 | * A list of strategies to find classes. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | private static $strategies = [ |
||
24 | Strategy\PuliBetaStrategy::class, |
||
25 | Strategy\CommonClassesStrategy::class, |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * Discovery cache to make the second time we use discovery faster. |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | private static $cache = []; |
||
34 | |||
35 | /** |
||
36 | * Finds a class. |
||
37 | * |
||
38 | * @param string $type |
||
39 | * |
||
40 | * @return string|\Closure |
||
41 | * |
||
42 | * @throws DiscoveryFailedException |
||
43 | */ |
||
44 | protected static function findOneByType($type) |
||
76 | |||
77 | /** |
||
78 | * Get a value from cache. |
||
79 | * |
||
80 | * @param string $type |
||
81 | * |
||
82 | * @return string|null |
||
83 | */ |
||
84 | private static function getFromCache($type) |
||
97 | |||
98 | /** |
||
99 | * Store a value in cache. |
||
100 | * |
||
101 | * @param string $type |
||
102 | * @param string $class |
||
103 | */ |
||
104 | private static function storeInCache($type, $class) |
||
108 | |||
109 | /** |
||
110 | * Set new strategies and clear the cache. |
||
111 | * |
||
112 | * @param array $strategies |
||
113 | */ |
||
114 | public static function setStrategies(array $strategies) |
||
119 | |||
120 | /** |
||
121 | * Clear the cache. |
||
122 | */ |
||
123 | public static function clearCache() |
||
127 | |||
128 | /** |
||
129 | * Evaulates conditions to boolean. |
||
130 | * |
||
131 | * @param mixed $condition |
||
132 | * |
||
133 | * @return bool |
||
134 | */ |
||
135 | protected static function evaluateCondition($condition) |
||
157 | |||
158 | /** |
||
159 | * Get an instance of the $class. |
||
160 | * |
||
161 | * @param string|\Closure $class A FQN of a class or a closure that instantiate the class. |
||
162 | * |
||
163 | * @return object |
||
164 | */ |
||
165 | protected static function instantiateClass($class) |
||
181 | } |
||
182 |