|
9 | 9 | use Okapi\CodeTransformer\Core\DI;
|
10 | 10 | use Okapi\CodeTransformer\Core\Exception\Kernel\DirectKernelInitializationException;
|
11 | 11 | use Okapi\CodeTransformer\Core\Options;
|
| 12 | +use Okapi\CodeTransformer\Core\Options\Environment; |
12 | 13 | use Okapi\CodeTransformer\Core\StreamFilter;
|
13 | 14 | use Okapi\Singleton\Singleton;
|
14 | 15 |
|
|
18 | 19 | * This class is the heart of the Code Transformer library.
|
19 | 20 | * It manages an environment for Code Transformation.
|
20 | 21 | *
|
21 |
| - * 1. Extends this class and define a list of transformers in the |
22 |
| - * `$transformers` property. |
23 |
| - * 2. Call the `init()` method early in the application lifecycle. |
| 22 | + * 1. Extend this class and define a list of transformers in the |
| 23 | + * {@link $transformers} property. |
| 24 | + * 2. Call the {@link init()} method early in the application lifecycle. |
| 25 | + * |
| 26 | + * If you want to modify the kernel options dynamically, override the |
| 27 | + * {@link configureOptions()} method. |
24 | 28 | */
|
25 | 29 | abstract class CodeTransformerKernel
|
26 | 30 | {
|
@@ -80,6 +84,19 @@ public function __construct() {}
|
80 | 84 | */
|
81 | 85 | protected bool $debug = false;
|
82 | 86 |
|
| 87 | + /** |
| 88 | + * The environment in which the application is running. |
| 89 | + * <br><b>Default:</b> {@link Environment::DEVELOPMENT}<br><br> |
| 90 | + * |
| 91 | + * If {@link Environment::PRODUCTION}, the cache will not be checked for |
| 92 | + * updates (better performance).<br> |
| 93 | + * If {@link Environment::DEVELOPMENT}, the cache will be checked for |
| 94 | + * updates (better development experience). |
| 95 | + * |
| 96 | + * @var Environment |
| 97 | + */ |
| 98 | + protected Environment $environment = Environment::DEVELOPMENT; |
| 99 | + |
83 | 100 | /**
|
84 | 101 | * Throw an exception if the kernel is initialized twice.
|
85 | 102 | * <br><b>Default:</b> {@link false}<br>
|
@@ -135,6 +152,7 @@ public static function init(): void
|
135 | 152 |
|
136 | 153 | // Initialize the services
|
137 | 154 | $instance->preInit();
|
| 155 | + $instance->configureOptions(); |
138 | 156 | $instance->registerServices();
|
139 | 157 | $instance->registerAutoloadInterceptor();
|
140 | 158 |
|
@@ -163,12 +181,23 @@ protected function preInit(): void
|
163 | 181 | cacheDir: $this->cacheDir,
|
164 | 182 | cacheFileMode: $this->cacheFileMode,
|
165 | 183 | debug: $this->debug,
|
| 184 | + environment: $this->environment, |
166 | 185 | );
|
167 | 186 |
|
168 | 187 | // Add the transformers
|
169 | 188 | $this->transformerManager->addTransformers($this->transformers);
|
170 | 189 | }
|
171 | 190 |
|
| 191 | + /** |
| 192 | + * Configure or modify kernel options. |
| 193 | + * |
| 194 | + * @return void |
| 195 | + */ |
| 196 | + protected function configureOptions(): void |
| 197 | + { |
| 198 | + // Override this method to configure the options dynamically |
| 199 | + } |
| 200 | + |
172 | 201 | /**
|
173 | 202 | * Register the services.
|
174 | 203 | *
|
|
0 commit comments