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

Cecilapp / Cecil / 5045835811

pending completion
5045835811

Pull #1697

github

GitHub
Merge c3e3c7443 into a16355c73
Pull Request #1697: perf: native_function_invocation

321 of 321 new or added lines in 62 files covered. (100.0%)

2784 of 4121 relevant lines covered (67.56%)

0.68 hits per line

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

92.0
/src/Generator/VirtualPages.php
1
<?php
2

3
declare(strict_types=1);
4

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

14
namespace Cecil\Generator;
15

16
use Cecil\Collection\Page\Page;
17
use Cecil\Collection\Page\Type;
18
use Cecil\Exception\RuntimeException;
19

20
/**
21
 * Class Generator\VirtualPages.
22
 */
23
class VirtualPages extends AbstractGenerator implements GeneratorInterface
24
{
25
    protected $configKey = 'virtualpages';
26

27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function generate(): void
31
    {
32
        $pagesConfig = $this->collectPagesFromConfig($this->configKey);
1✔
33

34
        if (!$pagesConfig) {
1✔
35
            return;
×
36
        }
37

38
        foreach ($pagesConfig as $frontmatter) {
1✔
39
            if (isset($frontmatter['published']) && $frontmatter['published'] === false) {
1✔
40
                continue;
1✔
41
            }
42
            if (!isset($frontmatter['path'])) {
1✔
43
                throw new RuntimeException(sprintf('Each pages in "%s" config\'s section must have a "path".', $this->configKey));
×
44
            }
45
            $path = Page::slugify($frontmatter['path']);
1✔
46
            foreach ($this->config->getLanguages() as $language) {
1✔
47
                $pageId = !empty($path) ? $path : 'index';
1✔
48
                if ($language['code'] !== $this->config->getLanguageDefault()) {
1✔
49
                    $pageId .= '.' . $language['code'];
1✔
50
                    // disable multilingual support
51
                    if (isset($frontmatter['multilingual']) && $frontmatter['multilingual'] === false) {
1✔
52
                        continue;
1✔
53
                    }
54
                }
55
                // abord if the page id already exists
56
                if ($this->builder->getPages()->has($pageId)) {
1✔
57
                    continue;
1✔
58
                }
59
                $page = (new Page($pageId))
1✔
60
                    ->setPath($path)
1✔
61
                    ->setType(Type::PAGE)
1✔
62
                    ->setVariable('language', $language['code'])
1✔
63
                    ->setVariable('langref', $path);
1✔
64
                $page->setVariables($frontmatter);
1✔
65
                $this->generatedPages->add($page);
1✔
66
            }
67
        }
68
    }
69

70
    /**
71
     * Collects virtual pages configuration.
72
     */
73
    private function collectPagesFromConfig(string $configKey): ?array
74
    {
75
        return $this->config->get($configKey);
1✔
76
    }
77
}
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