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

Cecilapp / Cecil / 21676346600

04 Feb 2026 02:57PM UTC coverage: 82.378% (-0.2%) from 82.577%
21676346600

push

github

ArnaudLigny
Persist assets to temp file in debug mode

When running in debug mode, append asset paths to a temporary file (assets-<buildId>.txt) under the configured destination/TMP_DIR in addToAssetsList, and read that file in getAssetsList. If the file read fails, getAssetsList returns an empty array. Non-debug behavior (using the in-memory $assets array) is unchanged. This ensures the assets list is persisted to disk for debug builds.

14 of 15 new or added lines in 1 file covered. (93.33%)

40 existing lines in 4 files now uncovered.

3319 of 4029 relevant lines covered (82.38%)

0.82 hits per line

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

88.0
/src/Renderer/Site.php
1
<?php
2

3
/**
4
 * This file is part of Cecil.
5
 *
6
 * (c) Arnaud Ligny <arnaud@ligny.fr>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace Cecil\Renderer;
15

16
use Cecil\Builder;
17
use Cecil\Collection\Page\Page as CollectionPage;
18

19
/**
20
 * Site renderer class.
21
 *
22
 * This class implements the \ArrayAccess interface to allow access to site
23
 * properties using array syntax. It provides access to various site-related
24
 * properties such as pages, menus, taxonomies, and language settings.
25
 * It also provides methods to retrieve specific pages and collections of pages
26
 * based on the current language or all pages regardless of their translation.
27
 */
28
class Site implements \ArrayAccess
29
{
30
    /**
31
     * Builder object.
32
     * @var Builder
33
     */
34
    protected $builder;
35
    /**
36
     * Configuration object.
37
     * @var \Cecil\Config
38
     */
39
    protected $config;
40
    /**
41
     * Current language code.
42
     * @var string
43
     */
44
    protected $language;
45

46
    public function __construct(Builder $builder, string $language)
47
    {
48
        $this->builder = $builder;
1✔
49
        $this->config = $this->builder->getConfig();
1✔
50
        $this->language = $language;
1✔
51
    }
52

53
    /**
54
     * Implement ArrayAccess.
55
     *
56
     * @param mixed $offset
57
     *
58
     * @return bool
59
     */
60
    #[\ReturnTypeWillChange]
61
    public function offsetExists($offset): bool
62
    {
63
        // special cases
64
        switch ($offset) {
65
            case 'menus':
1✔
66
            case 'taxonomies':
1✔
67
            case 'home':
1✔
68
            case 'debug':
1✔
69
            case 'build':
1✔
70
                return true;
1✔
71
        }
72

73
        return $this->config->has($offset);
1✔
74
    }
75

76
    /**
77
     * Implements \ArrayAccess.
78
     *
79
     * @param mixed $offset
80
     *
81
     * @return mixed|null
82
     */
83
    #[\ReturnTypeWillChange]
84
    public function offsetGet($offset)
85
    {
86
        // If it's a built-in variable: dot not fetch data from config raw
87
        switch ($offset) {
88
            case 'pages':
1✔
89
                return $this->getPages();
1✔
90
            case 'menus':
1✔
91
                return $this->builder->getMenus($this->language);
1✔
92
            case 'taxonomies':
1✔
93
                return $this->builder->getTaxonomies($this->language);
1✔
94
            case 'data':
1✔
95
                return $this->builder->getData($this->language);
1✔
96
            case 'static':
1✔
97
                return $this->builder->getStatic();
1✔
98
            case 'language':
1✔
99
                return new Language($this->config, $this->language);
1✔
100
            case 'home':
1✔
101
                return 'index';
1✔
102
            case 'debug':
1✔
UNCOV
103
                return $this->builder->isDebug();
×
104
            case 'build':
1✔
105
                return Builder::getBuildId();
1✔
106
        }
107

108
        return $this->config->get($offset, $this->language);
1✔
109
    }
110

111
    /**
112
     * Implements \ArrayAccess.
113
     *
114
     * @param mixed $offset
115
     * @param mixed $value
116
     *
117
     * @SuppressWarnings(UnusedFormalParameter)
118
     */
119
    #[\ReturnTypeWillChange]
120
    public function offsetSet($offset, $value): void
121
    {
UNCOV
122
    }
×
123

124
    /**
125
     * Implements \ArrayAccess.
126
     *
127
     * @param mixed $offset
128
     *
129
     * @SuppressWarnings(UnusedFormalParameter)
130
     */
131
    #[\ReturnTypeWillChange]
132
    public function offsetUnset($offset): void
133
    {
UNCOV
134
    }
×
135

136
    /**
137
     * Returns a page for the provided language or the current one provided.
138
     *
139
     * @throws \DomainException
140
     */
141
    public function getPage(string $id, ?string $language = null): ?CollectionPage
142
    {
143
        $pageId = $id;
1✔
144
        $language = $language ?? $this->language;
1✔
145

146
        if ($language !== null && $language != $this->config->getLanguageDefault()) {
1✔
147
            $pageId = "$language/$id";
1✔
148
        }
149

150
        if ($this->builder->getPages()->has($pageId) === false) {
1✔
151
            // if multilingual == false
152
            if ($this->builder->getPages()->has($id) && $this->builder->getPages()->get($id)->getVariable('multilingual') === false) {
1✔
UNCOV
153
                return $this->builder->getPages()->get($id);
×
154
            }
155

156
            return null;
1✔
157
        }
158

159
        return $this->builder->getPages()->get($pageId);
1✔
160
    }
161

162
    /**
163
     * Returns all pages, in the current language.
164
     */
165
    public function getPages(): \Cecil\Collection\Page\Collection
166
    {
167
        return $this->builder->getPages()->filter(function (CollectionPage $page) {
1✔
168
            // We should fix case of virtual pages without language
169
            if (
170
                $page->getVariable('language') === null
1✔
171
                && $this->language == $this->config->getLanguageDefault()
1✔
172
            ) {
UNCOV
173
                return true;
×
174
            }
175

176
            return $page->getVariable('language') == $this->language;
1✔
177
        });
1✔
178
    }
179

180
    /**
181
     * Returns all pages, regardless of their translation.
182
     */
183
    public function getAllPages(): \Cecil\Collection\Page\Collection
184
    {
185
        return $this->builder->getPages();
1✔
186
    }
187

188
    /**
189
     * Alias of getAllPages().
190
     */
191
    public function getPagesIntl(): \Cecil\Collection\Page\Collection
192
    {
UNCOV
193
        return $this->getAllPages();
×
194
    }
195

196
    /**
197
     * Returns current time.
198
     */
199
    public function getTime(): int
200
    {
201
        return time();
1✔
202
    }
203

204
    /**
205
     * Returns the property value(s) of an output format.
206
     */
207
    public function getOutputProperty(string $name, string $property): string|array|null
208
    {
209
        return $this->config->getOutputFormatProperty($name, $property);
1✔
210
    }
211
}
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