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

tito10047 / progressive-image-bundle / 20675431244

03 Jan 2026 09:29AM UTC coverage: 88.617% (+0.3%) from 88.338%
20675431244

push

github

tito10047
add TTL support for image caching: implement configurable TTL handling in cache services, adapt Twig components, and update tests to validate TTL functionality

12 of 12 new or added lines in 3 files covered. (100.0%)

120 existing lines in 9 files now uncovered.

615 of 694 relevant lines covered (88.62%)

184.23 hits per line

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

100.0
/src/Event/KernelResponseEventListener.php
1
<?php
2

3
/*
4
 * This file is part of the Progressive Image Bundle.
5
 *
6
 * (c) Jozef Môstka <https://github.com/tito10047/progressive-image-bundle>
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
namespace Tito10047\ProgressiveImageBundle\Event;
13

14
use Symfony\Component\HttpKernel\Event\ResponseEvent;
15
use Tito10047\ProgressiveImageBundle\Service\PreloadCollector;
16

17
final class KernelResponseEventListener
18
{
19
    public function __construct(
20
        private readonly PreloadCollector $preloadCollector,
21
    ) {
22
    }
143✔
23

24
    public function __invoke(ResponseEvent $event): void
25
    {
26
        $response = $event->getResponse();
143✔
27

28
        $preloads = $this->preloadCollector->getUrls();
143✔
29
        if (empty($preloads)) {
143✔
30
            return;
85✔
31
        }
32

33
        $links = [];
58✔
34
        foreach ($preloads as $url => $attr) {
58✔
35
            $link = sprintf('<%s>; rel=preload; as=%s; fetchpriority=%s',
58✔
36
                $url, $attr['as'], $attr['priority']);
58✔
37
            if (!empty($attr['imagesrcset'])) {
58✔
UNCOV
38
                $link .= sprintf('; imagesrcset="%s"', $attr['imagesrcset']);
14✔
39
            }
40
            if (!empty($attr['imagesizes'])) {
58✔
UNCOV
41
                $link .= sprintf('; imagesizes="%s"', $attr['imagesizes']);
14✔
42
            }
43
            $links[] = $link;
58✔
44
        }
45
        $response->headers->set('Link', implode(', ', $links), false);
58✔
46

47
        $content = $response->getContent();
58✔
48

49
        $html = '';
58✔
50
        foreach ($preloads as $url => $attr) {
58✔
51
            $html .= sprintf('<link rel="preload" href="%s" as="%s" fetchpriority="%s"',
58✔
52
                $url, $attr['as'], $attr['priority']);
58✔
53
            if (!empty($attr['imagesrcset'])) {
58✔
UNCOV
54
                $html .= sprintf(' imagesrcset="%s"', $attr['imagesrcset']);
14✔
55
            }
56
            if (!empty($attr['imagesizes'])) {
58✔
UNCOV
57
                $html .= sprintf(' imagesizes="%s"', $attr['imagesizes']);
14✔
58
            }
59
            $html .= '>';
58✔
60
        }
61

62
        $newContent = str_replace('</head>', $html.'</head>', $content);
58✔
63
        $response->setContent($newContent);
58✔
64
    }
65
}
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