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) |
||
99 | |||
100 | /** |
||
101 | * Store a value in cache. |
||
102 | * |
||
103 | * @param string $type |
||
104 | * @param string $class |
||
105 | */ |
||
106 | private static function storeInCache($type, $class) |
||
110 | |||
111 | /** |
||
112 | * Set new strategies and clear the cache. |
||
113 | * |
||
114 | * @param array $strategies string array of fully qualified class name to a DiscoveryStrategy |
||
115 | */ |
||
116 | public static function setStrategies(array $strategies) |
||
121 | |||
122 | /** |
||
123 | * Append a strategy at the end of the strategy queue. |
||
124 | * |
||
125 | * @param string $strategy Fully qualified class name to a DiscoveryStrategy |
||
126 | */ |
||
127 | public static function appendStrategy($strategy) |
||
132 | |||
133 | /** |
||
134 | * Prepend a strategy at the beginning of the strategy queue. |
||
135 | * |
||
136 | * @param string $strategy Fully qualified class name to a DiscoveryStrategy |
||
137 | */ |
||
138 | public static function prependStrategy($strategy) |
||
143 | |||
144 | /** |
||
145 | * Clear the cache. |
||
146 | */ |
||
147 | public static function clearCache() |
||
151 | |||
152 | /** |
||
153 | * Evaulates conditions to boolean. |
||
154 | * |
||
155 | * @param mixed $condition |
||
156 | * |
||
157 | * @return bool |
||
158 | */ |
||
159 | protected static function evaluateCondition($condition) |
||
181 | |||
182 | /** |
||
183 | * Get an instance of the $class. |
||
184 | * |
||
185 | * @param string|\Closure $class A FQN of a class or a closure that instantiate the class. |
||
186 | * |
||
187 | * @return object |
||
188 | */ |
||
189 | protected static function instantiateClass($class) |
||
205 | } |
||
206 |