1 | <?php |
||
25 | class GoAspectContainer extends Container implements AspectContainer |
||
26 | { |
||
27 | /** |
||
28 | * List of resources for application |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $resources = []; |
||
33 | |||
34 | /** |
||
35 | * Cached timestamp for resources |
||
36 | * |
||
37 | * @var integer |
||
38 | */ |
||
39 | protected $maxTimestamp = 0; |
||
40 | |||
41 | /** |
||
42 | * Constructor for container |
||
43 | */ |
||
44 | 10 | public function __construct() |
|
45 | { |
||
46 | // Register all services in the container |
||
47 | $this->share('aspect.loader', function(Container $container) { |
||
|
|||
48 | 2 | $aspectLoader = new AspectLoader( |
|
49 | $container, |
||
50 | 2 | $container->get('aspect.annotation.reader') |
|
51 | ); |
||
52 | 2 | $lexer = $container->get('aspect.pointcut.lexer'); |
|
53 | 2 | $parser = $container->get('aspect.pointcut.parser'); |
|
54 | |||
55 | // Register general aspect loader extension |
||
56 | 2 | $aspectLoader->registerLoaderExtension(new GeneralAspectLoaderExtension($lexer, $parser)); |
|
57 | 2 | $aspectLoader->registerLoaderExtension(new IntroductionAspectExtension($lexer, $parser)); |
|
58 | |||
59 | 2 | return $aspectLoader; |
|
60 | 10 | }); |
|
61 | |||
62 | $this->share('aspect.cached.loader', function(Container $container) { |
||
63 | $cachedAspectLoader = new CachedAspectLoader( |
||
64 | $container, |
||
65 | 'aspect.loader', |
||
66 | $container->get('kernel.options') |
||
67 | ); |
||
68 | |||
69 | return $cachedAspectLoader; |
||
70 | 10 | }); |
|
71 | |||
72 | $this->share('aspect.advisor.accessor', function(Container $container) { |
||
73 | return new LazyAdvisorAccessor( |
||
74 | $container, |
||
75 | $container->get('aspect.cached.loader') |
||
76 | ); |
||
77 | 10 | }); |
|
78 | |||
79 | $this->share('aspect.advice_matcher', function(Container $container) { |
||
80 | 1 | return new AdviceMatcher( |
|
81 | 1 | $container->get('aspect.loader'), |
|
82 | 1 | $container->get('kernel.interceptFunctions') |
|
83 | ); |
||
84 | 10 | }); |
|
85 | |||
86 | $this->share('aspect.annotation.reader', function(Container $container) { |
||
87 | 4 | $options = $container->get('kernel.options'); |
|
88 | 4 | $reader = new AnnotationReader(); |
|
89 | 4 | if (!empty($options['cacheDir'])) { |
|
90 | $reader = new FileCacheReader( |
||
91 | $reader, |
||
92 | $options['cacheDir'] . DIRECTORY_SEPARATOR . '_annotations' . DIRECTORY_SEPARATOR, |
||
93 | $options['debug'], |
||
94 | 0777 & (~$options['cacheFileMode']) |
||
95 | ); |
||
96 | } |
||
97 | |||
98 | 4 | return $reader; |
|
99 | 10 | }); |
|
100 | $this->share('aspect.cache.path.manager', function(Container $container) { |
||
101 | return new CachePathManager($container->get('kernel')); |
||
102 | 10 | }); |
|
103 | |||
104 | // Pointcut services |
||
105 | $this->share('aspect.pointcut.lexer', function() { |
||
106 | 3 | return new PointcutLexer(); |
|
107 | 10 | }); |
|
108 | 10 | $this->share('aspect.pointcut.parser', function(Container $container) { |
|
109 | 3 | return new PointcutParser( |
|
110 | 3 | new PointcutGrammar( |
|
111 | $container, |
||
112 | 3 | $container->get('aspect.annotation.reader') |
|
113 | ) |
||
114 | ); |
||
115 | 10 | }); |
|
116 | 10 | } |
|
117 | |||
118 | /** |
||
119 | * Returns a pointcut by identifier |
||
120 | * |
||
121 | * @param string $id Pointcut identifier |
||
122 | * |
||
123 | * @return Aop\Pointcut |
||
124 | */ |
||
125 | 1 | public function getPointcut($id) |
|
129 | |||
130 | /** |
||
131 | * Store the pointcut in the container |
||
132 | * |
||
133 | * @param Aop\Pointcut $pointcut Instance |
||
134 | * @param string $id Key for pointcut |
||
135 | */ |
||
136 | 1 | public function registerPointcut(Aop\Pointcut $pointcut, $id) |
|
140 | |||
141 | /** |
||
142 | * Returns an advisor by identifier |
||
143 | * |
||
144 | * @param string $id Advisor identifier |
||
145 | * |
||
146 | * @return Aop\Advisor |
||
147 | */ |
||
148 | public function getAdvisor($id) |
||
152 | |||
153 | /** |
||
154 | * Store the advisor in the container |
||
155 | * |
||
156 | * @param Aop\Advisor $advisor Instance |
||
157 | * @param string $id Key for advisor |
||
158 | */ |
||
159 | 1 | public function registerAdvisor(Aop\Advisor $advisor, $id) |
|
163 | |||
164 | /** |
||
165 | * Returns an aspect by id or class name |
||
166 | * |
||
167 | * @param string $aspectName Aspect name |
||
168 | * |
||
169 | * @return Aop\Aspect |
||
170 | */ |
||
171 | 1 | public function getAspect($aspectName) |
|
175 | |||
176 | /** |
||
177 | * Register an aspect in the container |
||
178 | * |
||
179 | * @param Aop\Aspect $aspect Instance of concrete aspect |
||
180 | */ |
||
181 | 1 | public function registerAspect(Aop\Aspect $aspect) |
|
187 | |||
188 | /** |
||
189 | * Add an AOP resource to the container |
||
190 | * |
||
191 | * Resources is used to check the freshness of AOP cache |
||
192 | */ |
||
193 | 2 | public function addResource($resource) |
|
198 | |||
199 | /** |
||
200 | * Returns list of AOP resources |
||
201 | * |
||
202 | * @return array |
||
203 | */ |
||
204 | public function getResources() |
||
208 | |||
209 | /** |
||
210 | * Checks the freshness of AOP cache |
||
211 | * |
||
212 | * @param integer $timestamp |
||
213 | * |
||
214 | * @return bool Whether or not concrete file is fresh |
||
215 | */ |
||
216 | 1 | public function isFresh($timestamp) |
|
224 | } |
||
225 |