77use Closure ;
88use Tempest \Console \ConsoleCommand ;
99use Tempest \Console \HasConsole ;
10+ use Tempest \Container \Container ;
1011use Tempest \Container \GenericContainer ;
1112use Tempest \Core \FrameworkKernel ;
12- use Tempest \Core \Kernel ;
1313use Tempest \Discovery \BootDiscovery ;
14+ use Tempest \Discovery \ClearDiscoveryCache ;
1415use Tempest \Discovery \DiscoveryCache ;
1516use Tempest \Discovery \DiscoveryCacheStrategy ;
1617use Tempest \Discovery \DiscoveryConfig ;
18+ use Tempest \Discovery \GenerateDiscoveryCache ;
1719
1820if (class_exists (\Tempest \Console \ConsoleCommand::class)) {
1921 final readonly class DiscoveryGenerateCommand
2022 {
2123 use HasConsole;
2224
2325 public function __construct (
24- private DiscoveryConfig $ discoveryConfig ,
2526 private FrameworkKernel $ kernel ,
27+ private Container $ container ,
28+ private DiscoveryConfig $ discoveryConfig ,
2629 private DiscoveryCache $ discoveryCache ,
30+ private GenerateDiscoveryCache $ generateDiscoveryCache ,
31+ private ClearDiscoveryCache $ clearDiscoveryCache ,
2732 ) {}
2833
2934 #[ConsoleCommand(
@@ -41,20 +46,26 @@ public function __invoke(): void
4146 return ;
4247 }
4348
44- $ this ->clearDiscoveryCache ();
45-
4649 $ this ->console ->task (
47- label: " Generating discovery cache using the ` { $ strategy -> value } ` strategy " ,
48- handler: fn (Closure $ log ) => $ this ->generateDiscoveryCache ( $ strategy , $ log ),
50+ label: ' Clearing discovery cache' ,
51+ handler: fn () => ( $ this ->clearDiscoveryCache )( $ this -> discoveryCache ),
4952 );
50- }
5153
52- public function clearDiscoveryCache (): void
53- {
54- $ this ->console ->call (DiscoveryClearCommand::class);
54+ $ this ->console ->task (
55+ label: "Generating {$ strategy ->value } discovery cache " ,
56+ handler: function () use ($ strategy ) {
57+ $ kernel = $ this ->resolveKernel ();
58+
59+ ($ this ->generateDiscoveryCache )(
60+ $ kernel ->container ,
61+ $ kernel ->discoveryConfig ,
62+ $ this ->discoveryCache ->withStrategy ($ strategy ),
63+ );
64+ },
65+ );
5566 }
5667
57- public function generateDiscoveryCache (DiscoveryCacheStrategy $ strategy , Closure $ log ): void
68+ private function generateDiscoveryCache (DiscoveryCacheStrategy $ strategy , Closure $ log ): void
5869 {
5970 $ kernel = $ this ->resolveKernel ();
6071
@@ -74,7 +85,7 @@ public function generateDiscoveryCache(DiscoveryCacheStrategy $strategy, Closure
7485 $ this ->discoveryCache ->storeStrategy ($ strategy );
7586 }
7687
77- public function resolveKernel (): Kernel
88+ private function resolveKernel (): FrameworkKernel
7889 {
7990 $ container = new GenericContainer ();
8091 $ container ->singleton (DiscoveryConfig::class, $ this ->discoveryConfig );
@@ -86,6 +97,7 @@ public function resolveKernel(): Kernel
8697 )
8798 ->registerKernel ()
8899 ->loadComposer ()
100+ ->loadDiscoveryConfig ()
89101 ->loadConfig ();
90102 }
91103 }
0 commit comments