1 | <?php |
||
40 | class Addendum implements LoggerAwareInterface |
||
41 | { |
||
42 | |||
43 | const DefaultInstanceId = 'addendum'; |
||
1 ignored issue
–
show
|
|||
44 | |||
45 | /** |
||
46 | * Runtime path |
||
47 | * @var string |
||
48 | */ |
||
49 | public $runtimePath = 'runtime'; |
||
50 | |||
51 | /** |
||
52 | * Namespaces to check for annotations. |
||
53 | * By default global and addendum namespace is included. |
||
54 | * @var string[] |
||
55 | */ |
||
56 | public $namespaces = [ |
||
57 | '\\', |
||
58 | TargetAnnotation::Ns |
||
59 | ]; |
||
60 | |||
61 | /** |
||
62 | * Translatable annotations |
||
63 | * TODO This should be moved to `maslosoft/addendum-i18n-extractor` |
||
64 | * @var string[] |
||
65 | */ |
||
66 | public $i18nAnnotations = [ |
||
67 | 'Label', |
||
68 | 'Description' |
||
69 | ]; |
||
70 | |||
71 | /** |
||
72 | * Plugins collection |
||
73 | * @var AddendumPlugins|mixed[] |
||
74 | */ |
||
75 | public $plugins = [ |
||
76 | 'matcher' => [ |
||
77 | ClassLiteralMatcher::class => [ |
||
78 | UseResolverDecorator::class |
||
79 | ] |
||
80 | ] |
||
81 | ]; |
||
82 | |||
83 | /** |
||
84 | * Current instance id |
||
85 | * @var string |
||
86 | */ |
||
87 | protected $instanceId = self::DefaultInstanceId; |
||
88 | |||
89 | /** |
||
90 | * DI |
||
91 | * @var EmbeDi |
||
92 | */ |
||
93 | protected $di = null; |
||
94 | |||
95 | /** |
||
96 | * Logger |
||
97 | * @var LoggerInterface |
||
98 | */ |
||
99 | private $_logger; |
||
100 | |||
101 | /** |
||
102 | * Cache for resolved annotations class names. |
||
103 | * Key is shor annotation name. |
||
104 | * @var string[] |
||
105 | */ |
||
106 | private static $_classnames = []; |
||
107 | |||
108 | /** |
||
109 | * This holds information about all declared classes implementing AnnotatedInterface. |
||
110 | * @see AnnotatedInterface |
||
111 | * @var string[] |
||
112 | */ |
||
113 | private static $_annotations = []; |
||
114 | |||
115 | /** |
||
116 | * Reflection annotated class cache |
||
117 | * @var ReflectionAnnotatedClass[] |
||
118 | */ |
||
119 | private static $_localCache = []; |
||
120 | |||
121 | /** |
||
122 | * Version holder |
||
123 | * @var string |
||
124 | */ |
||
125 | private static $_version = null; |
||
126 | |||
127 | /** |
||
128 | * Addendum instances |
||
129 | * @var Addendum[] |
||
130 | */ |
||
131 | private static $_a = []; |
||
132 | |||
133 | /** |
||
134 | * |
||
135 | * @param string $instanceId |
||
136 | */ |
||
137 | public function __construct($instanceId = self::DefaultInstanceId) |
||
145 | 72 | ||
146 | 72 | /** |
|
147 | * Get flyweight addendum instance of `Addendum`. |
||
148 | 72 | * Only one instance will be created for each `$instanceId` |
|
149 | 72 | * |
|
150 | 72 | * @param string $instanceId |
|
151 | * @return Addendum |
||
152 | */ |
||
153 | public static function fly($instanceId = self::DefaultInstanceId) |
||
161 | 52 | ||
162 | 52 | /** |
|
163 | 2 | * Get current addendum version. |
|
164 | 2 | * |
|
165 | 52 | * @return string |
|
166 | */ |
||
167 | public function getVersion() |
||
175 | |||
176 | /** |
||
177 | * Initialize addendum and store configuration. |
||
178 | * This should be called upon first intstance creation. |
||
179 | * |
||
180 | * @return Addendum |
||
181 | */ |
||
182 | public function init() |
||
191 | 2 | ||
192 | /** |
||
193 | * Chech if class could have annotations. |
||
194 | 2 | * **NOTE:** |
|
195 | 2 | * > This does not check check if class have annotations. It only checks if it implements `AnnotatedInterface` |
|
196 | * @param string|object $class |
||
197 | * @return bool |
||
198 | */ |
||
199 | public function hasAnnotations($class) |
||
203 | |||
204 | /** |
||
205 | 48 | * Use $class name or object to annotate class |
|
206 | * @param string|object $class |
||
207 | 48 | * @return ReflectionAnnotatedMethod|ReflectionAnnotatedProperty|ReflectionAnnotatedClass |
|
208 | */ |
||
209 | public function annotate($class) |
||
219 | 48 | ||
220 | /** |
||
221 | * Set logger |
||
222 | 48 | * |
|
223 | 38 | * @param LoggerInterface $logger |
|
224 | * @return Addendum |
||
225 | */ |
||
226 | public function setLogger(LoggerInterface $logger) |
||
231 | |||
232 | 72 | /** |
|
233 | * Get logger |
||
234 | * |
||
235 | 72 | * @return LoggerInterface logger |
|
236 | */ |
||
237 | public function getLogger() |
||
245 | |||
246 | /** |
||
247 | * Add annotations namespace. |
||
248 | * Every added namespace will be included in annotation name resolving for current instance. |
||
249 | * |
||
250 | * @param string $ns |
||
251 | * @renturn Addendum |
||
252 | */ |
||
253 | public function addNamespace($ns) |
||
271 | 4 | ||
272 | 4 | /** |
|
273 | 4 | * Add many annotaion namespaces. |
|
274 | 4 | * This is same as `addNamespace`, in that difference that many namespaces at once can be added. |
|
275 | 6 | * |
|
276 | * It accepts array of namespaces as param: |
||
277 | * ```php |
||
278 | * $nss = [ |
||
279 | * 'Maslosoft\Addendum\Annotations', |
||
280 | * 'Maslosoft\Mangan\Annotations' |
||
281 | * ]; |
||
282 | * ``` |
||
283 | * |
||
284 | * @param string[] $nss |
||
285 | * @return Addendum |
||
286 | */ |
||
287 | public function addNamespaces($nss) |
||
295 | 48 | ||
296 | /** |
||
297 | 6 | * Clear entire annotations cache. |
|
298 | 48 | */ |
|
299 | 48 | public static function cacheClear() |
|
308 | 6 | ||
309 | 6 | /** |
|
310 | 6 | * TODO This should not be static |
|
311 | 6 | * @param \Reflector $reflection |
|
312 | 6 | * @return mixed[] |
|
313 | 6 | */ |
|
314 | 6 | public static function getDocComment(\Reflector $reflection) |
|
331 | |||
332 | /** |
||
333 | * Set raw parsing mode |
||
334 | * @deprecated Since 4.0.4 this has no effect |
||
335 | * @param bool $enabled |
||
336 | */ |
||
337 | public static function setRawMode($enabled = true) |
||
341 | 50 | ||
342 | 50 | /** |
|
343 | 4 | * Resolve annotation class name to prefixed annotation class name |
|
344 | 4 | * |
|
345 | 4 | * @param string|bool $class |
|
346 | 4 | * @return string |
|
347 | 50 | */ |
|
348 | public static function resolveClassName($class) |
||
386 | 28 | ||
387 | 28 | private static function _getDeclaredAnnotations() |
|
402 | 28 | ||
403 | } |
||
404 |