1 | <?php |
||
27 | abstract class AspectKernel |
||
28 | { |
||
29 | |||
30 | /** |
||
31 | * Version of kernel |
||
32 | */ |
||
33 | const VERSION = '1.0.0'; |
||
34 | |||
35 | /** |
||
36 | * Kernel options |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $options = array( |
||
41 | 'features' => 0 |
||
42 | ); |
||
43 | |||
44 | /** |
||
45 | * Single instance of kernel |
||
46 | * |
||
47 | * @var null|static |
||
48 | */ |
||
49 | protected static $instance = null; |
||
50 | |||
51 | /** |
||
52 | * Default class name for container, can be redefined in children |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | protected static $containerClass = GoAspectContainer::class; |
||
57 | |||
58 | /** |
||
59 | * Flag to determine if kernel was already initialized or not |
||
60 | * |
||
61 | * @var bool |
||
62 | */ |
||
63 | protected $wasInitialized = false; |
||
64 | |||
65 | /** |
||
66 | * Aspect container instance |
||
67 | * |
||
68 | * @var null|AspectContainer |
||
69 | */ |
||
70 | protected $container = null; |
||
71 | |||
72 | /** |
||
73 | * Protected constructor is used to prevent direct creation, but allows customization if needed |
||
74 | */ |
||
75 | protected function __construct() {} |
||
76 | |||
77 | /** |
||
78 | * Returns the single instance of kernel |
||
79 | * |
||
80 | * @return static |
||
81 | */ |
||
82 | public static function getInstance() |
||
90 | |||
91 | /** |
||
92 | * Init the kernel and make adjustments |
||
93 | * |
||
94 | * @param array $options Associative array of options for kernel |
||
95 | */ |
||
96 | public function init(array $options = []) |
||
130 | |||
131 | /** |
||
132 | * Returns an aspect container |
||
133 | * |
||
134 | * @return null|AspectContainer |
||
135 | */ |
||
136 | 6 | public function getContainer() |
|
140 | |||
141 | /** |
||
142 | * Checks if kernel configuration has enabled specific feature |
||
143 | * |
||
144 | * @param integer $featureToCheck See Go\Aop\Features enumeration class for features |
||
145 | * |
||
146 | * @return bool Whether specific feature enabled or not |
||
147 | */ |
||
148 | public function hasFeature($featureToCheck) |
||
152 | |||
153 | /** |
||
154 | * Returns list of kernel options |
||
155 | * |
||
156 | * @return array |
||
157 | */ |
||
158 | public function getOptions() |
||
162 | |||
163 | /** |
||
164 | * Returns default options for kernel. Available options: |
||
165 | * |
||
166 | * debug - boolean Determines whether or not kernel is in debug mode |
||
167 | * appDir - string Path to the application root directory. |
||
168 | * cacheDir - string Path to the cache directory where compiled classes will be stored |
||
169 | * cacheFileMode - integer Binary mask of permission bits that is set to cache files |
||
170 | * features - integer Binary mask of features |
||
171 | * includePaths - array Whitelist of directories where aspects should be applied. Empty for everywhere. |
||
172 | * excludePaths - array Blacklist of directories or files where aspects shouldn't be applied. |
||
173 | * |
||
174 | * @return array |
||
175 | */ |
||
176 | protected function getDefaultOptions() |
||
190 | |||
191 | |||
192 | /** |
||
193 | * Normalizes options for the kernel |
||
194 | * |
||
195 | * @param array $options List of options |
||
196 | * |
||
197 | * @return array |
||
198 | */ |
||
199 | protected function normalizeOptions(array $options) |
||
215 | |||
216 | /** |
||
217 | * Configure an AspectContainer with advisors, aspects and pointcuts |
||
218 | * |
||
219 | * @param AspectContainer $container |
||
220 | * |
||
221 | * @return void |
||
222 | */ |
||
223 | abstract protected function configureAop(AspectContainer $container); |
||
224 | |||
225 | /** |
||
226 | * Returns list of source transformers, that will be applied to the PHP source |
||
227 | * |
||
228 | * @return array|SourceTransformer[] |
||
229 | */ |
||
230 | protected function registerTransformers() |
||
262 | |||
263 | /** |
||
264 | * Add resources for kernel |
||
265 | * |
||
266 | * @param AspectContainer $container |
||
267 | */ |
||
268 | protected function addKernelResourcesToContainer(AspectContainer $container) |
||
276 | } |
||
277 |