1 | <?php |
||
31 | abstract class AspectKernel |
||
32 | { |
||
33 | |||
34 | /** |
||
35 | * Version of kernel |
||
36 | */ |
||
37 | public const VERSION = '2.1.0'; |
||
38 | |||
39 | /** |
||
40 | * Kernel options |
||
41 | */ |
||
42 | protected $options = [ |
||
43 | 'features' => 0 |
||
44 | ]; |
||
45 | |||
46 | /** |
||
47 | * Single instance of kernel |
||
48 | * |
||
49 | * @var static |
||
50 | */ |
||
51 | protected static $instance; |
||
52 | |||
53 | /** |
||
54 | * Default class name for container, can be redefined in children |
||
55 | */ |
||
56 | protected static $containerClass = GoAspectContainer::class; |
||
57 | |||
58 | /** |
||
59 | * Flag to determine if kernel was already initialized or not |
||
60 | */ |
||
61 | protected $wasInitialized = false; |
||
62 | |||
63 | /** |
||
64 | * Aspect container instance |
||
65 | * |
||
66 | * @var AspectContainer |
||
67 | */ |
||
68 | protected $container; |
||
69 | |||
70 | /** |
||
71 | * Protected constructor is used to prevent direct creation, but allows customization if needed |
||
72 | */ |
||
73 | protected function __construct() {} |
||
74 | |||
75 | /** |
||
76 | * Returns the single instance of kernel |
||
77 | */ |
||
78 | 1 | public static function getInstance(): self |
|
86 | |||
87 | /** |
||
88 | * Init the kernel and make adjustments |
||
89 | * |
||
90 | * @param array $options Associative array of options for kernel |
||
91 | */ |
||
92 | 1 | public function init(array $options = []) |
|
126 | |||
127 | /** |
||
128 | * Returns an aspect container |
||
129 | */ |
||
130 | 1 | public function getContainer(): AspectContainer |
|
134 | |||
135 | /** |
||
136 | * Checks if kernel configuration has enabled specific feature |
||
137 | * |
||
138 | * @see \Go\Aop\Features enumeration class for features |
||
139 | */ |
||
140 | 1 | public function hasFeature(int $featureToCheck): bool |
|
144 | |||
145 | /** |
||
146 | * Returns list of kernel options |
||
147 | */ |
||
148 | 1 | public function getOptions(): array |
|
152 | |||
153 | /** |
||
154 | * Returns default options for kernel. Available options: |
||
155 | * |
||
156 | * debug - boolean Determines whether or not kernel is in debug mode |
||
157 | * appDir - string Path to the application root directory. |
||
158 | * cacheDir - string Path to the cache directory where compiled classes will be stored |
||
159 | * cacheFileMode - integer Binary mask of permission bits that is set to cache files |
||
160 | * annotationCache - Doctrine\Common\Cache\Cache. If not provided, Doctrine\Common\Cache\PhpFileCache is used. |
||
161 | * features - integer Binary mask of features |
||
162 | * includePaths - array Whitelist of directories where aspects should be applied. Empty for everywhere. |
||
163 | * excludePaths - array Blacklist of directories or files where aspects shouldn't be applied. |
||
164 | */ |
||
165 | 1 | protected function getDefaultOptions(): array |
|
179 | |||
180 | |||
181 | /** |
||
182 | * Normalizes options for the kernel |
||
183 | * |
||
184 | * @param array $options List of options |
||
185 | */ |
||
186 | 1 | protected function normalizeOptions(array $options): array |
|
205 | |||
206 | /** |
||
207 | * Configures an AspectContainer with advisors, aspects and pointcuts |
||
208 | */ |
||
209 | abstract protected function configureAop(AspectContainer $container); |
||
210 | |||
211 | /** |
||
212 | * Returns list of source transformers, that will be applied to the PHP source |
||
213 | * |
||
214 | * @return SourceTransformer[] |
||
215 | * @internal This method is internal and should not be used outside this project |
||
216 | */ |
||
217 | 1 | protected function registerTransformers(): array |
|
218 | { |
||
219 | 1 | $cacheManager = $this->getContainer()->get('aspect.cache.path.manager'); |
|
220 | 1 | $filterInjector = new FilterInjectorTransformer($this, SourceTransformingLoader::getId(), $cacheManager); |
|
221 | 1 | $magicTransformer = new MagicConstantTransformer($this); |
|
222 | |||
223 | $sourceTransformers = function () use ($filterInjector, $magicTransformer, $cacheManager) { |
||
224 | 1 | $transformers = []; |
|
225 | 1 | if ($this->hasFeature(Features::INTERCEPT_INITIALIZATIONS)) { |
|
226 | $transformers[] = new ConstructorExecutionTransformer(); |
||
227 | } |
||
228 | 1 | if ($this->hasFeature(Features::INTERCEPT_INCLUDES)) { |
|
229 | $transformers[] = $filterInjector; |
||
230 | } |
||
231 | 1 | $transformers[] = new SelfValueTransformer($this); |
|
232 | 1 | $transformers[] = new WeavingTransformer( |
|
233 | 1 | $this, |
|
234 | 1 | $this->container->get('aspect.advice_matcher'), |
|
235 | 1 | $cacheManager, |
|
236 | 1 | $this->container->get('aspect.cached.loader') |
|
237 | ); |
||
238 | 1 | $transformers[] = $magicTransformer; |
|
239 | |||
240 | 1 | return $transformers; |
|
241 | 1 | }; |
|
242 | |||
243 | return [ |
||
244 | 1 | new CachingTransformer($this, $sourceTransformers, $cacheManager) |
|
245 | ]; |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * Add resources of kernel to the container |
||
250 | */ |
||
251 | 1 | protected function addKernelResourcesToContainer(AspectContainer $container): void |
|
259 | } |
||
260 |