• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tempestphp / tempest-framework / 14024978163

23 Mar 2025 05:55PM UTC coverage: 79.391% (-0.05%) from 79.441%
14024978163

push

github

web-flow
feat(view): cache Blade and Twig templates in internal storage (#1061)

2 of 2 new or added lines in 2 files covered. (100.0%)

912 existing lines in 110 files now uncovered.

10478 of 13198 relevant lines covered (79.39%)

91.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Tempest/Core/src/Commands/DiscoveryGenerateCommand.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Core\Commands;
6

7
use Closure;
8
use Tempest\Cache\DiscoveryCacheStrategy;
9
use Tempest\Console\ConsoleCommand;
10
use Tempest\Console\HasConsole;
11
use Tempest\Container\Container;
12
use Tempest\Container\GenericContainer;
13
use Tempest\Core\DiscoveryCache;
14
use Tempest\Core\FrameworkKernel;
15
use Tempest\Core\Kernel;
16
use Tempest\Core\Kernel\LoadDiscoveryClasses;
17

18
use function Tempest\env;
19

20
final readonly class DiscoveryGenerateCommand
21
{
22
    use HasConsole;
23

UNCOV
24
    public function __construct(
×
25
        private Kernel $kernel,
26
        private DiscoveryCache $discoveryCache,
27
    ) {
UNCOV
28
    }
×
29

UNCOV
30
    #[ConsoleCommand(name: 'discovery:generate', description: 'Compile and cache all discovery according to the configured discovery caching strategy')]
×
31
    public function __invoke(): void
32
    {
UNCOV
33
        $strategy = $this->resolveDiscoveryCacheStrategy();
×
34

UNCOV
35
        if ($strategy === DiscoveryCacheStrategy::NONE) {
×
36
            $this->info('Discovery cache disabled, nothing to generate.');
×
37

UNCOV
38
            return;
×
39
        }
40

UNCOV
41
        $this->clearDiscoveryCache();
×
42

UNCOV
43
        $this->console->task(
×
44
            label: "Generating discovery cache using the {$strategy->value} strategy",
×
UNCOV
45
            handler: fn (Closure $log) => $this->generateDiscoveryCache($strategy, $log),
×
46
        );
×
47

UNCOV
48
        $this->discoveryCache->storeStrategy($strategy);
×
49
    }
50

51
    public function clearDiscoveryCache(): void
×
52
    {
53
        $this->console->call(DiscoveryClearCommand::class);
×
54
    }
55

56
    public function generateDiscoveryCache(DiscoveryCacheStrategy $strategy, Closure $log): void
×
57
    {
58
        $kernel = $this->resolveKernel();
×
59

60
        $loadDiscoveryClasses = new LoadDiscoveryClasses(
×
UNCOV
61
            kernel: $kernel,
×
62
            container: $kernel->container,
×
63
            discoveryCache: $this->discoveryCache,
×
64
        );
×
65

66
        $discoveries = $loadDiscoveryClasses->build();
×
67

68
        foreach ($discoveries as $discovery) {
×
UNCOV
69
            $log($discovery::class);
×
70
            $discoveryItems = $discovery->getItems();
×
71

72
            if ($strategy === DiscoveryCacheStrategy::PARTIAL) {
×
73
                $discoveryItems = $discoveryItems->onlyVendor();
×
74
            }
75

76
            $this->discoveryCache->store($discovery, $discoveryItems);
×
77
        }
78
    }
79

UNCOV
80
    private function resolveDiscoveryCacheStrategy(): DiscoveryCacheStrategy
×
81
    {
UNCOV
82
        $cache = env('CACHE');
×
83

84
        if ($cache !== null) {
×
85
            return DiscoveryCacheStrategy::make($cache);
×
86
        }
87

UNCOV
88
        return DiscoveryCacheStrategy::make(env('DISCOVERY_CACHE'));
×
89
    }
90

UNCOV
91
    public function resolveKernel(): Kernel
×
92
    {
UNCOV
93
        $container = new GenericContainer();
×
94
        $container->singleton(Container::class, $container);
×
95

UNCOV
96
        return new FrameworkKernel(
×
UNCOV
97
            root: $this->kernel->root,
×
98
            discoveryLocations: $this->kernel->discoveryLocations,
×
UNCOV
99
            container: $container,
×
UNCOV
100
        )
×
101
            ->registerKernel()
×
UNCOV
102
            ->loadComposer()
×
103
            ->loadConfig();
×
104
    }
105
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc