1 | <?php |
||
29 | abstract class AspectKernel |
||
30 | { |
||
31 | |||
32 | /** |
||
33 | * Version of kernel |
||
34 | */ |
||
35 | const VERSION = '1.0.0'; |
||
36 | |||
37 | /** |
||
38 | * Kernel options |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | protected $options = array( |
||
43 | 'features' => 0 |
||
44 | ); |
||
45 | |||
46 | /** |
||
47 | * Single instance of kernel |
||
48 | * |
||
49 | * @var null|static |
||
50 | */ |
||
51 | protected static $instance = null; |
||
52 | |||
53 | /** |
||
54 | * Default class name for container, can be redefined in children |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | protected static $containerClass = GoAspectContainer::class; |
||
59 | |||
60 | /** |
||
61 | * Flag to determine if kernel was already initialized or not |
||
62 | * |
||
63 | * @var bool |
||
64 | */ |
||
65 | protected $wasInitialized = false; |
||
66 | |||
67 | /** |
||
68 | * Aspect container instance |
||
69 | * |
||
70 | * @var null|AspectContainer |
||
71 | */ |
||
72 | protected $container = null; |
||
73 | |||
74 | /** |
||
75 | * Protected constructor is used to prevent direct creation, but allows customization if needed |
||
76 | */ |
||
77 | protected function __construct() {} |
||
78 | |||
79 | /** |
||
80 | * Returns the single instance of kernel |
||
81 | * |
||
82 | * @return AspectKernel |
||
83 | */ |
||
84 | public static function getInstance() |
||
92 | |||
93 | /** |
||
94 | * Init the kernel and make adjustments |
||
95 | * |
||
96 | * @param array $options Associative array of options for kernel |
||
97 | */ |
||
98 | public function init(array $options = []) |
||
132 | |||
133 | /** |
||
134 | * Returns an aspect container |
||
135 | * |
||
136 | * @return null|AspectContainer |
||
137 | */ |
||
138 | 6 | public function getContainer() |
|
142 | |||
143 | /** |
||
144 | * Returns a default bit mask of features by checking PHP version |
||
145 | * |
||
146 | * @return int |
||
147 | */ |
||
148 | public static function getDefaultFeatures() |
||
157 | |||
158 | /** |
||
159 | * Checks if kernel configuration has enabled specific feature |
||
160 | * |
||
161 | * @param integer $featureToCheck See Go\Aop\Features enumeration class for features |
||
162 | * |
||
163 | * @return bool Whether specific feature enabled or not |
||
164 | */ |
||
165 | public function hasFeature($featureToCheck) |
||
169 | |||
170 | /** |
||
171 | * Returns list of kernel options |
||
172 | * |
||
173 | * @return array |
||
174 | */ |
||
175 | public function getOptions() |
||
179 | |||
180 | /** |
||
181 | * Returns default options for kernel. Available options: |
||
182 | * |
||
183 | * debug - boolean Determines whether or not kernel is in debug mode |
||
184 | * appDir - string Path to the application root directory. |
||
185 | * cacheDir - string Path to the cache directory where compiled classes will be stored |
||
186 | * cacheFileMode - integer Binary mask of permission bits that is set to cache files |
||
187 | * features - integer Binary mask of features |
||
188 | * includePaths - array Whitelist of directories where aspects should be applied. Empty for everywhere. |
||
189 | * excludePaths - array Blacklist of directories or files where aspects shouldn't be applied. |
||
190 | * |
||
191 | * @return array |
||
192 | */ |
||
193 | protected function getDefaultOptions() |
||
209 | |||
210 | |||
211 | /** |
||
212 | * Normalizes options for the kernel |
||
213 | * |
||
214 | * @param array $options List of options |
||
215 | * |
||
216 | * @return array |
||
217 | */ |
||
218 | protected function normalizeOptions(array $options) |
||
233 | |||
234 | /** |
||
235 | * Configure an AspectContainer with advisors, aspects and pointcuts |
||
236 | * |
||
237 | * @param AspectContainer $container |
||
238 | * |
||
239 | * @return void |
||
240 | */ |
||
241 | abstract protected function configureAop(AspectContainer $container); |
||
242 | |||
243 | /** |
||
244 | * Returns list of source transformers, that will be applied to the PHP source |
||
245 | * |
||
246 | * @return array|SourceTransformer[] |
||
247 | */ |
||
248 | protected function registerTransformers() |
||
283 | |||
284 | /** |
||
285 | * Add resources for kernel |
||
286 | * |
||
287 | * @param AspectContainer $container |
||
288 | */ |
||
289 | protected function addKernelResourcesToContainer(AspectContainer $container) |
||
297 | } |
||
298 |