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

tempestphp / tempest-framework / 12021710761

25 Nov 2024 06:54PM UTC coverage: 79.441% (-2.6%) from 81.993%
12021710761

push

github

web-flow
ci: close stale issues and pull requests

7879 of 9918 relevant lines covered (79.44%)

61.32 hits per line

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

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

3
declare(strict_types=1);
4

5
namespace Tempest\View;
6

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

14
final class ViewComponentDiscovery implements Discovery, DiscoversPath
15
{
16
    use IsDiscovery;
17

18
    public function __construct(
382✔
19
        private readonly ViewConfig $viewConfig,
20
    ) {
21
    }
382✔
22

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

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

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

41
        if (! is_file($path)) {
1✔
42
            return;
×
43
        }
44

45
        $content = ltrim(file_get_contents($path));
1✔
46

47
        if (! str_contains($content, '<x-component name=')) {
1✔
48
            return;
×
49
        }
50

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

57
        if (! $matches['name']) {
1✔
58
            return;
×
59
        }
60

61
        $this->discoveryItems->add($location, [
1✔
62
            $matches['name'],
1✔
63
            new AnonymousViewComponent(
1✔
64
                contents: $matches['header'] . $matches['view'],
1✔
65
                file: $path,
1✔
66
            ),
1✔
67
        ]);
1✔
68

69
    }
70

71
    public function apply(): void
382✔
72
    {
73
        foreach ($this->discoveryItems as [$name, $viewComponent]) {
382✔
74
            if (is_string($viewComponent)) {
382✔
75
                $viewComponent = new ClassReflector($viewComponent);
382✔
76
            }
77

78
            $this->viewConfig->addViewComponent(
382✔
79
                name: $name,
382✔
80
                viewComponent: $viewComponent,
382✔
81
            );
382✔
82
        }
83
    }
84
}
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