• 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

78.72
/src/Tempest/View/src/ViewComponentDiscovery.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\View;
6

7
use Tempest\Discovery\DiscoversPath;
8
use Tempest\Discovery\Discovery;
9
use Tempest\Discovery\DiscoveryLocation;
10
use Tempest\Discovery\IsDiscovery;
11
use Tempest\Reflection\ClassReflector;
12
use Tempest\View\Components\AnonymousViewComponent;
13

14
use function Tempest\Support\str;
15

16
final class ViewComponentDiscovery implements Discovery, DiscoversPath
17
{
18
    use IsDiscovery;
19

20
    public function __construct(
659✔
21
        private readonly ViewConfig $viewConfig,
22
    ) {
23
    }
659✔
24

25
    public function discover(DiscoveryLocation $location, ClassReflector $class): void
×
26
    {
UNCOV
27
        if (! $class->implements(ViewComponent::class)) {
×
UNCOV
28
            return;
×
29
        }
30

31
        $this->discoveryItems->add($location, [
×
32
            forward_static_call($class->getName() . '::getName'),
×
UNCOV
33
            $class->getName(),
×
UNCOV
34
        ]);
×
35
    }
36

37
    public function discoverPath(DiscoveryLocation $location, string $path): void
3✔
38
    {
39
        if (! str_ends_with($path, '.view.php')) {
3✔
UNCOV
40
            return;
×
41
        }
42

43
        if (! is_file($path)) {
3✔
UNCOV
44
            return;
×
45
        }
46

47
        $fileName = str(pathinfo($path, PATHINFO_FILENAME))->before('.');
3✔
48
        $contents = str(file_get_contents($path))->ltrim();
3✔
49

50
        preg_match(
3✔
51
            pattern: '/(?<header>(.|\n)*?)<x-component name="(?<name>[\w\-]+)">(?<view>(.|\n)*?)<\/x-component>/',
3✔
52
            subject: $contents->toString(),
3✔
53
            matches: $matches,
3✔
54
        );
3✔
55

56
        if ($fileName->startsWith('x-') && ! isset($matches['name'])) {
3✔
57
            $this->discoveryItems->add($location, [
1✔
58
                $fileName->toString(),
1✔
59
                new AnonymousViewComponent(
1✔
60
                    contents: $matches['view'] ?? $contents->toString(),
1✔
61
                    file: $path,
1✔
62
                ),
1✔
63
            ]);
1✔
64

65
            return;
1✔
66
        }
67

68
        if (! isset($matches['name'], $matches['header'])) {
2✔
UNCOV
69
            return;
×
70
        }
71

72
        $this->discoveryItems->add($location, [
2✔
73
            $matches['name'],
2✔
74
            new AnonymousViewComponent(
2✔
75
                contents: $matches['header'] . $matches['view'],
2✔
76
                file: $path,
2✔
77
            ),
2✔
78
        ]);
2✔
79
    }
80

81
    public function apply(): void
659✔
82
    {
83
        foreach ($this->discoveryItems as [$name, $viewComponent]) {
659✔
84
            if (is_string($viewComponent)) {
659✔
85
                $viewComponent = new ClassReflector($viewComponent);
659✔
86
            }
87

88
            $this->viewConfig->addViewComponent(
659✔
89
                name: $name,
659✔
90
                viewComponent: $viewComponent,
659✔
91
            );
659✔
92
        }
93
    }
94
}
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