21
21
*/
22
22
23
23
namespace ElementaryFramework \Annotations ;
24
+ use ElementaryFramework \Annotations \Exceptions \AnnotationException ;
24
25
25
26
/**
26
- * Thin, static class with shortcut methods for inspection of Annotations
27
+ * Thin, static class with shortcut methods for inspection of annotations
27
28
*
28
29
* Using this static wrapper is optional - if your application uses a service container
29
30
* or a dependency injection container, you most likely want to configure an instance
@@ -34,29 +35,53 @@ abstract class Annotations
34
35
/**
35
36
* @var array Configuration for any public property of AnnotationManager.
36
37
*/
37
- public static $ config ;
38
+ private static $ _config ;
38
39
39
40
/**
40
41
* @var AnnotationManager Singleton AnnotationManager instance
41
42
*/
42
- private static $ manager ;
43
+ private static $ _manager ;
44
+
45
+ /**
46
+ * Sets a config value.
47
+ *
48
+ * @param string $key The config key.
49
+ * @param mixed $value The config value.
50
+ *
51
+ * @throws AnnotationException
52
+ */
53
+ public static function setConfig (string $ key , $ value )
54
+ {
55
+ switch ($ key ) {
56
+ case "autoload " :
57
+ case "cache " :
58
+ case "suffix " :
59
+ case "namespace " :
60
+ case "debug " :
61
+ self ::$ _config [$ key ] = $ value ;
62
+ break ;
63
+
64
+ default :
65
+ throw new AnnotationException ("Invalid config key. " );
66
+ }
67
+ }
43
68
44
69
/**
45
70
* @return AnnotationManager a singleton instance
46
71
*/
47
72
public static function getManager ()
48
73
{
49
- if (!isset (self ::$ manager )) {
50
- self ::$ manager = new AnnotationManager ;
74
+ if (!isset (self ::$ _manager )) {
75
+ self ::$ _manager = new AnnotationManager ;
51
76
}
52
77
53
- if (\is_array (self ::$ config )) {
54
- foreach (self ::$ config as $ key => $ value ) {
55
- self ::$ manager ->$ key = $ value ;
78
+ if (\is_array (self ::$ _config )) {
79
+ foreach (self ::$ _config as $ key => $ value ) {
80
+ self ::$ _manager ->$ key = $ value ;
56
81
}
57
82
}
58
83
59
- return self ::$ manager ;
84
+ return self ::$ _manager ;
60
85
}
61
86
62
87
/**
@@ -76,7 +101,7 @@ public static function getUsage(string $class): UsageAnnotation
76
101
}
77
102
78
103
/**
79
- * Inspects class Annotations
104
+ * Inspects class annotations
80
105
*
81
106
* @see AnnotationManager::getClassAnnotations()
82
107
*
@@ -93,7 +118,7 @@ public static function ofClass($class, string $type = null): array
93
118
}
94
119
95
120
/**
96
- * Inspects method Annotations
121
+ * Inspects method annotations
97
122
*
98
123
* @see AnnotationManager::getMethodAnnotations()
99
124
*
0 commit comments