1 | <?php |
||
11 | final class CacheEventHandlersCommand extends Command |
||
12 | { |
||
13 | protected $signature = 'event-sourcing:cache-event-handlers'; |
||
14 | |||
15 | protected $description = 'Cache all auto discovered event handlers'; |
||
16 | |||
17 | public function handle(Projectionist $projectionist, Filesystem $files): void |
||
18 | { |
||
19 | $this->info('Caching registered event handlers...'); |
||
20 | |||
21 | $projectionist->getProjectors() |
||
22 | ->merge($projectionist->getReactors()) |
||
23 | ->map(fn(EventHandler $eventHandler) => get_class($eventHandler)) |
||
|
|||
24 | ->pipe(function (Collection $eventHandlerClasses) use ($files) { |
||
25 | $cachePath = config('event-sourcing.cache_path'); |
||
26 | |||
27 | $files->makeDirectory($cachePath, 0755, true, true); |
||
28 | |||
29 | $files->put( |
||
30 | $cachePath.'/event-handlers.php', |
||
31 | '<?php return '.var_export($eventHandlerClasses->toArray(), true).';' |
||
32 | ); |
||
33 | }); |
||
34 | |||
35 | $this->info('All done!'); |
||
36 | } |
||
37 | } |
||
38 |