File tree Expand file tree Collapse file tree 3 files changed +26
-17
lines changed
Expand file tree Collapse file tree 3 files changed +26
-17
lines changed Original file line number Diff line number Diff line change 55namespace Tempest \Cache ;
66
77use Psr \Cache \CacheItemPoolInterface ;
8- use Tempest \Core \Commands \ DiscoveryGenerateCommand ;
8+ use Tempest \Core \DiscoveryCache ;
99use function Tempest \env ;
1010
1111final class CacheConfig
@@ -62,7 +62,7 @@ private function resolveDiscoveryCacheStrategy(): DiscoveryCacheStrategy
6262 return $ current ;
6363 }
6464
65- $ original = DiscoveryCacheStrategy::make (@file_get_contents (DiscoveryGenerateCommand ::CURRENT_DISCOVERY_STRATEGY ));
65+ $ original = DiscoveryCacheStrategy::make (@file_get_contents (DiscoveryCache ::CURRENT_DISCOVERY_STRATEGY ));
6666
6767 if ($ current !== $ original ) {
6868 return DiscoveryCacheStrategy::INVALID ;
Original file line number Diff line number Diff line change 1818{
1919 use HasConsole;
2020
21- public const string CURRENT_DISCOVERY_STRATEGY = __DIR__ . '/../.cache/current_discovery_strategy ' ;
22-
2321 public function __construct (
2422 private Kernel $ kernel ,
2523 private DiscoveryCache $ discoveryCache ,
@@ -45,7 +43,7 @@ public function __invoke(): void
4543
4644 $ this ->generateDiscoveryCache ($ strategy );
4745
48- $ this ->storeDiscoveryCacheStrategy ($ strategy );
46+ $ this ->discoveryCache -> storeStrategy ($ strategy );
4947 }
5048
5149 public function clearDiscoveryCache (): void
@@ -100,17 +98,6 @@ private function resolveDiscoveryCacheStrategy(): DiscoveryCacheStrategy
10098 return DiscoveryCacheStrategy::make (env ('DISCOVERY_CACHE ' ));
10199 }
102100
103- private function storeDiscoveryCacheStrategy (DiscoveryCacheStrategy $ strategy ): void
104- {
105- $ dir = dirname (self ::CURRENT_DISCOVERY_STRATEGY );
106-
107- if (! is_dir ($ dir )) {
108- mkdir ($ dir , recursive: true );
109- }
110-
111- file_put_contents (self ::CURRENT_DISCOVERY_STRATEGY , $ strategy ->value );
112- }
113-
114101 public function resolveKernel (): Kernel
115102 {
116103 $ container = new GenericContainer ();
Original file line number Diff line number Diff line change 1414
1515final class DiscoveryCache implements Cache
1616{
17- use IsCache;
17+ use IsCache {
18+ clear as parentClear;
19+ }
20+
21+ public const string CURRENT_DISCOVERY_STRATEGY = __DIR__ . '/.cache/current_discovery_strategy ' ;
1822
1923 private CacheItemPoolInterface $ pool ;
2024
@@ -68,8 +72,26 @@ public function isValid(): bool
6872 return $ this ->cacheConfig ->discoveryCache ->isValid ();
6973 }
7074
75+ public function clear (): void
76+ {
77+ $ this ->parentClear ();
78+
79+ $ this ->storeStrategy (DiscoveryCacheStrategy::INVALID );
80+ }
81+
7182 public function getStrategy (): DiscoveryCacheStrategy
7283 {
7384 return $ this ->cacheConfig ->discoveryCache ;
7485 }
86+
87+ public function storeStrategy (DiscoveryCacheStrategy $ strategy ): void
88+ {
89+ $ dir = dirname (self ::CURRENT_DISCOVERY_STRATEGY );
90+
91+ if (! is_dir ($ dir )) {
92+ mkdir ($ dir , recursive: true );
93+ }
94+
95+ file_put_contents (self ::CURRENT_DISCOVERY_STRATEGY , $ strategy ->value );
96+ }
7597}
You can’t perform that action at this time.
0 commit comments