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

heimrichhannot / contao-encore-bundle / 24727767148

21 Apr 2026 02:22PM UTC coverage: 77.228% (+3.6%) from 73.58%
24727767148

Pull #36

github

web-flow
Merge 3b71450f0 into 9616b9688
Pull Request #36: Add response context support

76 of 80 new or added lines in 6 files covered. (95.0%)

624 of 808 relevant lines covered (77.23%)

2.35 hits per line

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

92.42
/src/EntryPoint/EntryPointsBuilder.php
1
<?php
2

3
namespace HeimrichHannot\EncoreBundle\EntryPoint;
4

5
use Contao\CoreBundle\Routing\ResponseContext\ResponseContext;
6
use Contao\LayoutModel;
7
use Contao\PageModel;
8
use Contao\StringUtil;
9
use HeimrichHannot\EncoreBundle\Collection\EntryCollection;
10
use HeimrichHannot\EncoreBundle\Dca\EncoreEntriesSelectField;
11
use HeimrichHannot\EncoreBundle\Request\ResponseContext\EntryBag;
12
use HeimrichHannot\UtilsBundle\Util\Utils;
13

14
class EntryPointsBuilder
15
{
16
    private ?PageModel $pageModel = null;
17
    private string $pageField = '';
18
    private ?LayoutModel $layout = null;
19
    private string $layoutField = '';
20

21
    private array $available = [];
22
    private ?ResponseContext $responseContext = null;
23
    private ?EntryBag $entryBag = null;
24

25
    public function __construct(
26
        private readonly Utils $utils,
27
        private readonly EntryCollection $entryCollection,
28
    ) {
29
    }
2✔
30

31
    public function setPage(?PageModel $page, string $field = EncoreEntriesSelectField::NAME_DEFAULT): self
32
    {
33
        $this->pageModel = $page;
1✔
34
        $this->pageField = $field;
1✔
35

36
        return $this;
1✔
37
    }
38

39
    public function setLayout(?LayoutModel $layout, string $field = EncoreEntriesSelectField::NAME_DEFAULT): self
40
    {
41
        $this->layout = $layout;
1✔
42
        $this->layoutField = $field;
1✔
43

44
        return $this;
1✔
45
    }
46

47
    public function setResponseContext(?ResponseContext $responseContext): self
48
    {
49
        $this->responseContext = $responseContext;
1✔
50

51
        return $this;
1✔
52
    }
53

54
    public function setCustomBag(?EntryBag $entryBag): self
55
    {
56
        $this->entryBag = $entryBag;
1✔
57

58
        return $this;
1✔
59
    }
60

61
    public function build(): EntryPoints
62
    {
63
        $entryPoints = new EntryPoints();
1✔
64
        $available = $this->entryCollection->getEntries();
1✔
65
        if ([] !== $available) {
1✔
66
            $available = array_combine(array_column($available, 'name'), $available);
1✔
67
        }
68
        $this->available = $available;
1✔
69

70
        if ($this->responseContext && $this->responseContext->has(EntryBag::class)) {
1✔
71
            $this->addFromBag($entryPoints, $this->responseContext->get(EntryBag::class));
1✔
72
        }
73

74
        if ($this->pageModel && !$this->layout) {
1✔
75
            $this->pageModel->loadDetails();
×
76
            $layout = LayoutModel::findByPk($this->pageModel->layoutId ?? $this->pageModel->layout);
×
77
            if ($layout) {
×
78
                $this->setLayout($layout);
×
79
            }
80
        }
81

82
        if ($this->layout) {
1✔
83
            foreach (StringUtil::deserialize($this->layout->{$this->layoutField}, true) as $entrypoint) {
1✔
84
                $this->addEntryPoint(
1✔
85
                    entryPoints: $entryPoints,
1✔
86
                    name: $entrypoint['entry'] ?? '',
1✔
87
                    active: (bool) ($entrypoint['active'] ?? true),
1✔
88
                    origin: 'tl_layout.' . $this->layout->id,
1✔
89
                    extension: 'App',
1✔
90
                );
1✔
91
            }
92
        }
93

94
        if (null !== $this->pageModel) {
1✔
95
            $pages = $this->utils->model()->findParentsRecursively($this->pageModel, 'pid');
1✔
96
            $pages[] = $this->pageModel;
1✔
97

98
            foreach ($pages as $page) {
1✔
99
                foreach (StringUtil::deserialize($page->{$this->pageField}, true) as $entrypoint) {
1✔
100
                    $this->addEntryPoint(
1✔
101
                        entryPoints: $entryPoints,
1✔
102
                        name: $entrypoint['entry'] ?? '',
1✔
103
                        active: (bool) ($entrypoint['active'] ?? true),
1✔
104
                        origin: 'tl_page.' . $page->id,
1✔
105
                        extension: 'App',
1✔
106
                    );
1✔
107
                }
108
            }
109
        }
110

111
        if (null !== $this->entryBag) {
1✔
NEW
112
            $this->addFromBag($entryPoints, $this->entryBag);
×
113
        }
114

115
        return $entryPoints;
1✔
116
    }
117

118
    private function addFromBag(EntryPoints $entryPoints, EntryBag $bag): void
119
    {
120
        foreach ($bag->all() as $entry) {
1✔
121
            $this->addEntryPoint(
1✔
122
                entryPoints: $entryPoints,
1✔
123
                name: $entry->name,
1✔
124
                origin: $entry->origin,
1✔
125
                extension: $entry->extension,
1✔
126
            );
1✔
127
        }
128
    }
129

130
    private function addEntryPoint(EntryPoints $entryPoints, string $name, bool $active = true, string $origin = '', string $extension = ''): void
131
    {
132
        if ('' === $name) {
1✔
133
            return;
1✔
134
        }
135

136
        if (!isset($this->available[$name])) {
1✔
137
            return;
1✔
138
        }
139

140
        $entryPoints->add(new EntryPoint(
1✔
141
            name: $name,
1✔
142
            active: $active,
1✔
143
            head: $this->available[$name]['head'] ?? false,
1✔
144
            requiresCss: (bool) ($this->available[$name]['requires_css'] ?? true),
1✔
145
            origin: $origin,
1✔
146
            extension: $extension,
1✔
147
        ));
1✔
148
    }
149
}
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