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

heimrichhannot / contao-encore-bundle / 24726753103

21 Apr 2026 02:02PM UTC coverage: 77.273% (+3.7%) from 73.58%
24726753103

Pull #36

github

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

82 of 86 new or added lines in 7 files covered. (95.35%)

2 existing lines in 1 file now uncovered.

629 of 814 relevant lines covered (77.27%)

2.34 hits per line

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

92.06
/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;
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
        return $this;
1✔
58
    }
59

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

69
        if ($this->responseContext) {
1✔
70
            $bag = $this->responseContext->get(EntryBag::class);
1✔
71
            if ($bag instanceof EntryBag) {
1✔
72
                $this->addFromBag($entryPoints, $bag);
1✔
73
            }
74
        }
75

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

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

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

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

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

117
        return $entryPoints;
1✔
118
    }
119

120
    private function addFromBag(EntryPoints $entryPoints, EntryBag $bag): void
121
    {
122
        foreach ($bag->all() as $entry) {
1✔
123
            $entryPoints->add(EntryPoint::fromEntry($entry));
1✔
124
        }
125
    }
126

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

133
        if (!isset($this->available[$name])) {
1✔
134
            return;
1✔
135
        }
136

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