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

eliashaeussler / typo3-warming / 15509771334

07 Jun 2025 04:43PM UTC coverage: 86.535% (-4.1%) from 90.617%
15509771334

Pull #871

github

eliashaeussler
[FEATURE] Collect url metadata during cache warmup
Pull Request #871: [FEATURE] Collect url metadata during cache warmup

104 of 188 new or added lines in 9 files covered. (55.32%)

1 existing line in 1 file now uncovered.

1446 of 1671 relevant lines covered (86.54%)

9.25 hits per line

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

0.0
/Classes/Middleware/UrlMetadataEnricherMiddleware.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-2025 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\Middleware;
25

26
use EliasHaeussler\Typo3Warming\Http;
27
use Psr\Http\Message;
28
use Psr\Http\Server;
29
use TYPO3\CMS\Core;
30

31
/**
32
 * UrlMetadataEnricherMiddleware
33
 *
34
 * @author Elias Häußler <elias@haeussler.dev>
35
 * @license GPL-2.0-or-later
36
 */
37
final readonly class UrlMetadataEnricherMiddleware implements Server\MiddlewareInterface
38
{
NEW
39
    public function __construct(
×
40
        private Http\Message\UrlMetadataFactory $urlMetadataFactory,
NEW
41
    ) {}
×
42

43
    /**
44
     * @throws Core\Error\Http\StatusException
45
     * @throws Core\Http\ImmediateResponseException
46
     */
NEW
47
    public function process(
×
48
        Message\ServerRequestInterface $request,
49
        Server\RequestHandlerInterface $handler,
50
    ): Message\ResponseInterface {
NEW
51
        $metadata = $this->urlMetadataFactory->createForRequest($request);
×
52

NEW
53
        if ($metadata === null) {
×
NEW
54
            return $handler->handle($request);
×
55
        }
56

NEW
57
        $this->enrichUrlMetadata($metadata, $request);
×
58

59
        try {
NEW
60
            return $this->urlMetadataFactory->enrichResponse($handler->handle($request), $metadata);
×
NEW
61
        } catch (Core\Http\ImmediateResponseException|Core\Error\Http\StatusException $exception) {
×
NEW
62
            $this->urlMetadataFactory->enrichException($exception, $metadata);
×
63

NEW
64
            throw $exception;
×
65
        }
66
    }
67

NEW
68
    private function enrichUrlMetadata(Http\Message\UrlMetadata $metadata, Message\ServerRequestInterface $request): void
×
69
    {
NEW
70
        $pageArguments = $request->getAttribute('routing');
×
NEW
71
        $siteLanguage = $request->getAttribute('language');
×
72

NEW
73
        if ($pageArguments instanceof Core\Routing\PageArguments) {
×
NEW
74
            $metadata->pageId = $pageArguments->getPageId();
×
NEW
75
            $metadata->pageType = $pageArguments->getPageType();
×
76
        }
77

NEW
78
        if ($siteLanguage instanceof Core\Site\Entity\SiteLanguage) {
×
NEW
79
            $metadata->languageId = $siteLanguage->getLanguageId();
×
80
        }
81
    }
82
}
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

© 2025 Coveralls, Inc