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

tito10047 / progressive-image-bundle / 20721822894

05 Jan 2026 04:23PM UTC coverage: 89.724% (-0.07%) from 89.796%
20721822894

push

github

tito10047
add WebP support for responsive images: update URL generation, request handling, and CI dependencies

18 of 20 new or added lines in 3 files covered. (90.0%)

716 of 798 relevant lines covered (89.72%)

251.71 hits per line

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

92.59
/src/UrlGenerator/LiipImagineResponsiveImageUrlGenerator.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
declare(strict_types=1);
12

13
namespace Tito10047\ProgressiveImageBundle\UrlGenerator;
14

15
use Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException;
16
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
17
use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration;
18
use Symfony\Component\HttpFoundation\RequestStack;
19
use Symfony\Component\HttpFoundation\UriSigner;
20
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
21
use Symfony\Contracts\Cache\TagAwareCacheInterface;
22
use Tito10047\ProgressiveImageBundle\Service\LiipImagineRuntimeConfigGeneratorInterface;
23

24
final class LiipImagineResponsiveImageUrlGenerator implements ResponsiveImageUrlGeneratorInterface
25
{
26
    public function __construct(
27
        private readonly CacheManager $cacheManager,
28
        private readonly UrlGeneratorInterface $router,
29
        private readonly UriSigner $uriSigner,
30
        private readonly LiipImagineRuntimeConfigGeneratorInterface $runtimeConfigGenerator,
31
        private readonly FilterConfiguration $filterConfiguration,
32
                private readonly RequestStack $requestStack,
33
        private readonly ?TagAwareCacheInterface $cache,
34
                private readonly bool         $webpGenerate = false,
35
        private readonly ?string $filter = null,
36
    ) {
37
    }
392✔
38

39
        public function generateUrl(string $path, int $targetW, ?int $targetH = null, ?string $pointInterest = null): string
40
    {
41
        $targetH = $targetH ?? $targetW;
238✔
42
        $result = $this->runtimeConfigGenerator->generate($targetW, $targetH, $this->filter, $pointInterest);
238✔
43
        $filterName = $result['filterName'];
238✔
44
        $config = $result['config'];
238✔
45

46
        // Register runtime filter so LiipImagine can find it
47
        try {
48
            $this->filterConfiguration->get($filterName);
238✔
49
        } catch (NonExistingFilterException) {
196✔
50
            $this->filterConfiguration->set($filterName, $config);
196✔
51
        }
52

53
                $isWebpSupported = $this->isWebpSupported();
238✔
54
                $finalPath       = $path;
238✔
55
                if ($this->webpGenerate && $isWebpSupported) {
238✔
NEW
56
                        $finalPath = $path . '.webp';
×
57
                }
58

59
                if ($this->cacheManager->isStored($finalPath, $filterName)) {
238✔
60
                        return $this->cacheManager->resolve($finalPath, $filterName);
42✔
61
        }
62

63
        $this->cache?->invalidateTags(['pgi_tag_'.md5($path)]);
196✔
64

65
        $url = $this->router->generate('progressive_image_filter', [
196✔
66
            'path' => $path,
196✔
67
            'width' => $targetW,
196✔
68
            'height' => $targetH,
196✔
69
            'filter' => $this->filter,
196✔
70
            'pointInterest' => $pointInterest,
196✔
71
        ], UrlGeneratorInterface::ABSOLUTE_URL);
196✔
72

73
        return $this->uriSigner->sign($url);
196✔
74
        }
75

76
        private function isWebpSupported(): bool {
77
                $request = $this->requestStack->getCurrentRequest();
238✔
78
                if (null === $request) {
238✔
79
                        return false;
238✔
80
                }
81

NEW
82
                return false !== mb_stripos($request->headers->get('accept', ''), 'image/webp');
×
83
    }
84
}
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