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

heimrichhannot / contao-encore-bundle / 27198996514

09 Jun 2026 10:07AM UTC coverage: 75.679% (-1.9%) from 77.539%
27198996514

push

github

web-flow
Allow extension from App, various enhancements (#38)

28 of 68 new or added lines in 11 files covered. (41.18%)

3 existing lines in 2 files now uncovered.

641 of 847 relevant lines covered (75.68%)

2.27 hits per line

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

90.24
/src/Collection/EntryCollection.php
1
<?php
2

3
/*
4
 * Copyright (c) 2022 Heimrich & Hannot GmbH
5
 *
6
 * @license LGPL-3.0-or-later
7
 */
8

9
namespace HeimrichHannot\EncoreBundle\Collection;
10

11
use Contao\LayoutModel;
12
use HeimrichHannot\EncoreBundle\Exception\NoEntrypointsException;
13
use HeimrichHannot\EncoreContracts\EncoreEntry;
14
use Psr\Cache\CacheItemPoolInterface;
15

16
class EntryCollection
17
{
18
    private bool $useCache = false;
19
    private array $entries;
20

21
    public function __construct(
22
        private readonly ConfigurationCollection $configurationCollection,
23
        private array $bundleConfig,
24
        private readonly CacheItemPoolInterface $cache,
25
    ) {
26
        if ($this->bundleConfig['encore_cache_enabled'] ?? false) {
1✔
27
            $this->useCache = true;
1✔
28
        }
29
    }
30

31
    /**
32
     * Return all encore entries (from webpack config and registered via bundle).
33
     *
34
     * @throws NoEntrypointsException
35
     */
36
    public function getEntries(bool $asArray = true): array
37
    {
38
        if (!isset($this->entries)) {
1✔
39
            $this->entries = $this->mergeEntries(
1✔
40
                $this->bundleConfig['entrypoints_jsons'] ?? [],
1✔
41
                $this->configurationCollection->getJsEntries()
1✔
42
            );
1✔
43
        }
44

45
        if ($asArray) {
1✔
46
            $result = [];
1✔
47
            foreach ($this->entries as $entry) {
1✔
48
                $result[] = $entry->toArray();
1✔
49
            }
50

51
            return $result;
1✔
52
        }
53

UNCOV
54
        return $this->entries;
×
55
    }
56

57
    /**
58
     * @param array         $entrypointJsonFiles entrypoint json files
59
     * @param EncoreEntry[] $bundleConfigEntries Entries defined by encore bundle config
60
     *
61
     * @return EncoreEntry[]
62
     *
63
     * @throws NoEntrypointsException
64
     */
65
    private function mergeEntries(array $entrypointJsonFiles, array $bundleConfigEntries, ?LayoutModel $layout = null): array
66
    {
67
        foreach ($entrypointJsonFiles as $entrypointsJson) {
1✔
68
            $entrypoints = $this->parseEntrypoints($entrypointsJson);
1✔
69

70
            $entriesMap = [];
1✔
71
            foreach ($bundleConfigEntries as $entry) {
1✔
72
                if ('' === $entry->name) {
1✔
73
                    continue;
×
74
                }
75
                $entriesMap[$entry->name] = true;
1✔
76
            }
77

78
            foreach ($entrypoints as $name => $entrypoint) {
1✔
79
                // Only add entries that not already exist in the symfony config
80
                if (!isset($entriesMap[$name])) {
1✔
81
                    $bundleConfigEntries[] = EncoreEntry::create($name, '')
1✔
82
                        ->setRequiresCss(isset($entrypoint['css']));
1✔
83
                }
84
            }
85
        }
86

87
        return $bundleConfigEntries;
1✔
88
    }
89

90
    private function parseEntrypoints(string $entrypointsJson): array
91
    {
92
        $cached = null;
1✔
93
        if ($this->useCache) {
1✔
94
            // '_default' is the default cache key for single encore builds
95
            $cached = $this->cache->getItem('_default');
1✔
96

97
            if ($cached->isHit()) {
1✔
98
                $entriesData = $cached->get();
1✔
99

100
                return $entriesData['entrypoints'];
1✔
101
            }
102
        }
103

104
        if (!file_exists($entrypointsJson)) {
1✔
105
            throw new NoEntrypointsException(sprintf('Could not find the entrypoints.json: the file "%s" does not exist. Maybe you forgot to run encore command?', $entrypointsJson));
×
106
        }
107

108
        $entriesData = json_decode(file_get_contents($entrypointsJson), true);
1✔
109

110
        if (null === $entriesData) {
1✔
111
            throw new NoEntrypointsException(sprintf('Could not decode the "%s" file', $entrypointsJson));
×
112
        }
113

114
        if (!isset($entriesData['entrypoints'])) {
1✔
115
            throw new NoEntrypointsException(sprintf('There is no "entrypoints" key in "%s"', $entrypointsJson));
1✔
116
        }
117

118
        if ($this->useCache) {
1✔
119
            $this->cache->save($cached->set($entriesData));
1✔
120
        }
121

122
        return $entriesData['entrypoints'];
1✔
123
    }
124
}
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