|
2 | 2 |
|
3 | 3 | namespace Ecotone\Laravel; |
4 | 4 |
|
5 | | -use function class_exists; |
6 | | - |
7 | | -use const DIRECTORY_SEPARATOR; |
8 | | - |
9 | 5 | use Ecotone\AnnotationFinder\AnnotationFinderFactory; |
10 | 6 | use Ecotone\Messaging\Config\ConfiguredMessagingSystem; |
11 | 7 | use Ecotone\Messaging\Config\ConsoleCommandResultSet; |
|
19 | 15 | use Ecotone\Messaging\ConfigurationVariableService; |
20 | 16 | use Ecotone\Messaging\Gateway\ConsoleCommandRunner; |
21 | 17 | use Ecotone\Messaging\Handler\Recoverability\RetryTemplateBuilder; |
| 18 | +use Illuminate\Console\Events\CommandFinished; |
22 | 19 | use Illuminate\Foundation\Console\ClosureCommand; |
23 | 20 | use Illuminate\Support\Facades\App; |
24 | 21 | use Illuminate\Support\Facades\Artisan; |
25 | 22 | use Illuminate\Support\Facades\Config; |
26 | 23 | use Illuminate\Support\ServiceProvider; |
27 | 24 | use InvalidArgumentException; |
28 | 25 | use ReflectionMethod; |
| 26 | +use function class_exists; |
| 27 | +use const DIRECTORY_SEPARATOR; |
29 | 28 |
|
30 | 29 | /** |
31 | 30 | * licence Apache-2.0 |
@@ -55,13 +54,13 @@ public function register() |
55 | 54 |
|
56 | 55 | $errorChannel = Config::get('ecotone.defaultErrorChannel'); |
57 | 56 |
|
58 | | - $skippedModules = Config::get('ecotone.skippedModulePackageNames'); |
| 57 | + $skippedModules = Config::get('ecotone.skippedModulePackageNames') ?? []; |
59 | 58 | /** @TODO Ecotone 2.0 use ServiceContext to configure Laravel */ |
60 | 59 | $applicationConfiguration = ServiceConfiguration::createWithDefaults() |
61 | 60 | ->withEnvironment($environment) |
62 | 61 | ->withLoadCatalog(Config::get('ecotone.loadAppNamespaces') ? 'app' : '') |
63 | 62 | ->withFailFast(false) |
64 | | - ->withNamespaces(Config::get('ecotone.namespaces')) |
| 63 | + ->withNamespaces(Config::get('ecotone.namespaces') ?? []) |
65 | 64 | ->withSkippedModulePackageNames($skippedModules) |
66 | 65 | ->withCacheDirectoryPath($cacheDirectory); |
67 | 66 |
|
@@ -182,6 +181,9 @@ public function boot() |
182 | 181 | if (! $this->app->has('logger')) { |
183 | 182 | $this->app->singleton('logger', LaravelLogger::class); |
184 | 183 | } |
| 184 | + |
| 185 | + // Hook into Laravel's optimization commands to clear Ecotone cache |
| 186 | + $this->registerOptimizationHooks(); |
185 | 187 | } |
186 | 188 |
|
187 | 189 | private function getCacheDirectoryPath(): string |
@@ -296,4 +298,20 @@ public function prepareFromCache(mixed $useProductionCache, string $rootCatalog, |
296 | 298 |
|
297 | 299 | return [$serviceCacheConfiguration, $definitionHolder]; |
298 | 300 | } |
| 301 | + |
| 302 | + /** |
| 303 | + * Register hooks to clear Ecotone cache when Laravel optimization commands are run |
| 304 | + */ |
| 305 | + private function registerOptimizationHooks(): void |
| 306 | + { |
| 307 | + $this->app['events']->listen( |
| 308 | + CommandFinished::class, |
| 309 | + function ($event) { |
| 310 | + // Clear Ecotone cache when optimize commands finishes successfully |
| 311 | + if (in_array($event->command, ['optimize', 'optimize:clear', 'cache:clear']) && $event->exitCode === 0) { |
| 312 | + EcotoneCacheClear::clearEcotoneCacheDirectories($this->getCacheDirectoryPath()); |
| 313 | + } |
| 314 | + } |
| 315 | + ); |
| 316 | + } |
299 | 317 | } |
0 commit comments