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

eliashaeussler / typo3-warming / 24312657257

12 Apr 2026 05:48PM UTC coverage: 93.899% (-0.3%) from 94.229%
24312657257

push

github

web-flow
Merge pull request #1138 from eliashaeussler/fix/page-uri

6 of 9 new or added lines in 1 file covered. (66.67%)

3 existing lines in 1 file now uncovered.

1693 of 1803 relevant lines covered (93.9%)

12.56 hits per line

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

75.0
/Classes/Http/Message/PageUriBuilder.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "warming".
7
 *
8
 * Copyright (C) 2021-2026 Elias Häußler <elias@haeussler.dev>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace EliasHaeussler\Typo3Warming\Http\Message;
25

26
use EliasHaeussler\Typo3Warming\Security;
27
use Psr\Http\Message;
28
use Symfony\Component\DependencyInjection;
29
use TYPO3\CMS\Core;
30

31
/**
32
 * PageUriBuilder
33
 *
34
 * @author Elias Häußler <elias@haeussler.dev>
35
 * @license GPL-2.0-or-later
36
 */
37
final readonly class PageUriBuilder
38
{
39
    public function __construct(
17✔
40
        #[DependencyInjection\Attribute\Lazy]
41
        private Core\Domain\Repository\PageRepository $pageRepository,
42
        private Security\WarmupPermissionGuard $permissionGuard,
43
        private Core\Site\SiteFinder $siteFinder,
44
    ) {}
17✔
45

46
    /**
47
     * @param positive-int $pageId
48
     */
49
    public function build(int $pageId, ?int $languageId = null): ?Message\UriInterface
9✔
50
    {
51
        // Early return if page access is denied
52
        if (!$this->permissionGuard->canWarmupCacheOfPage($pageId, new Security\Context\PermissionContext($languageId))) {
9✔
53
            return null;
4✔
54
        }
55

56
        $page = $this->pageRepository->getPage($pageId);
5✔
57

58
        // Early return if page does not exist
59
        if ($page === []) {
5✔
UNCOV
60
            return null;
×
61
        }
62

63
        // Fetch page in default language, if necessary
64
        if (($page['sys_language_uid'] ?? 0) > 0) {
5✔
65
            return $this->build($page['l10n_parent'], $languageId);
1✔
66
        }
67

68
        try {
69
            // We don't use SiteRepository here, because it would return NULL on inaccessible pages,
70
            // which is undesirable here, because we're in page context (not site context)
71
            $site = $this->siteFinder->getSiteByPageId($pageId);
5✔
NEW
72
        } catch (Core\Exception\SiteNotFoundException) {
×
UNCOV
73
            return null;
×
74
        }
75

76
        // Resolve site language
77
        if ($languageId !== null) {
5✔
78
            try {
79
                $siteLanguage = $site->getLanguageById($languageId);
2✔
NEW
80
            } catch (\InvalidArgumentException) {
×
NEW
81
                return null;
×
82
            }
83
        } else {
84
            $siteLanguage = $site->getDefaultLanguage();
3✔
85
        }
86

87
        // Check if page is suitable for language
88
        if ($siteLanguage->getLanguageId() > 0) {
5✔
89
            $languageAspect = Core\Context\LanguageAspectFactory::createFromSiteLanguage($siteLanguage);
1✔
90
            $page = $this->pageRepository->getLanguageOverlay('pages', $page, $languageAspect);
1✔
91

92
            if ($page === null || !$this->pageRepository->isPageSuitableForLanguage($page, $languageAspect)) {
1✔
UNCOV
93
                return null;
×
94
            }
95
        }
96

97
        return $site->getRouter()->generateUri((string)$pageId, ['_language' => $siteLanguage]);
5✔
98
    }
99
}
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