-
-
Notifications
You must be signed in to change notification settings - Fork 161
Expand file tree
/
Copy pathGenerateDiscoveryCache.php
More file actions
37 lines (31 loc) · 1.02 KB
/
GenerateDiscoveryCache.php
File metadata and controls
37 lines (31 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace Tempest\Discovery;
use Psr\Container\ContainerInterface;
final class GenerateDiscoveryCache
{
/**
* @param class-string<Discovery>[]|null $discoveryClasses
* @param DiscoveryLocation[]|null $discoveryLocations
* @param Discovery[]|null $discoveries
*/
public function __invoke(
ContainerInterface $container,
DiscoveryConfig $config,
DiscoveryCache $cache,
?array $discoveryClasses = null,
?array $discoveryLocations = null,
?array $discoveries = null,
): void {
$originalStrategy = $cache->strategy;
$cache = $cache->withStrategy(DiscoveryCacheStrategy::NONE);
$discoveries ??= new BootDiscovery(
container: $container,
config: $config,
cache: $cache,
)->build($discoveryClasses, $discoveryLocations);
foreach ($config->locations as $location) {
$cache->store($location, $discoveries);
}
$cache->storeStrategy($originalStrategy);
}
}