diff --git a/config/ddd.php b/config/ddd.php index 0899794..ec67ad7 100644 --- a/config/ddd.php +++ b/config/ddd.php @@ -63,7 +63,10 @@ 'factories' => 'Database\Factories', ], - 'cache_folder' => 'bootstrap/cache/ddd/', + /* + * The folder where the domain cache files will be stored. + */ + 'cache_directory' => 'bootstrap/cache', 'autoload' => [ /* diff --git a/src/LaravelDDDServiceProvider.php b/src/LaravelDDDServiceProvider.php index fe8b301..311b6e2 100644 --- a/src/LaravelDDDServiceProvider.php +++ b/src/LaravelDDDServiceProvider.php @@ -2,6 +2,7 @@ namespace Lunarstorm\LaravelDDD; +use Illuminate\Support\Facades\Event; use Lunarstorm\LaravelDDD\Commands\InstallCommand; use Lunarstorm\LaravelDDD\Commands\MakeAction; use Lunarstorm\LaravelDDD\Commands\MakeBaseModel; @@ -11,6 +12,7 @@ use Lunarstorm\LaravelDDD\Commands\MakeModel; use Lunarstorm\LaravelDDD\Commands\MakeValueObject; use Lunarstorm\LaravelDDD\Commands\MakeViewModel; +use Lunarstorm\LaravelDDD\Support\CacheClearSubscriber; use Lunarstorm\LaravelDDD\Support\DomainAutoloader; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; @@ -71,5 +73,6 @@ public function packageBooted() public function packageRegistered() { (new DomainAutoloader())->autoload(); + Event::subscribe(CacheClearSubscriber::class); } } diff --git a/src/Support/CacheClearSubscriber.php b/src/Support/CacheClearSubscriber.php new file mode 100644 index 0000000..2217821 --- /dev/null +++ b/src/Support/CacheClearSubscriber.php @@ -0,0 +1,40 @@ +getMessage(), 'No such file or directory')) { + dump($exception->getMessage()); + throw $exception; + } + } + } + } + + /** + * Register the listeners for the subscriber. + * + * @param Dispatcher $events + * + * @return array + */ + public function subscribe(Dispatcher $events): void + { + $events->listen('cache:clearing', [$this, 'handle']); + } +} diff --git a/src/Support/DomainAutoloader.php b/src/Support/DomainAutoloader.php index bab8d6a..5cbff17 100644 --- a/src/Support/DomainAutoloader.php +++ b/src/Support/DomainAutoloader.php @@ -155,8 +155,10 @@ protected function extractDomainAndModelFromModelNamespace(string $modelName): a return []; } + protected function remember($fileName, $callback) { + // The cache is not available during booting, so we need to roll our own file based cache $cacheFilePath = base_path($this->cacheDirectory.'/'.$fileName.'.php'); $data = file_exists($cacheFilePath) ? include $cacheFilePath : null;