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

tito10047 / progressive-image-bundle / 21093331125

17 Jan 2026 11:10AM UTC coverage: 90.436% (-0.5%) from 90.889%
21093331125

push

github

web-flow
Merge pull request #4 from tito10047/responsive-strategy

change rendering stratety from <img> to <picture><source><img> for better responsive strategy

268 of 332 new or added lines in 19 files covered. (80.72%)

5 existing lines in 2 files now uncovered.

851 of 941 relevant lines covered (90.44%)

318.39 hits per line

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

100.0
/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
    ) {
36
    }
504✔
37

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

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

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

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

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

NEW
65
        $params = [
308✔
66
            'path' => $path,
308✔
67
            'width' => $targetW,
308✔
68
            'height' => $targetH,
308✔
NEW
69
            'filter' => $filter,
308✔
70
            'pointInterest' => $pointInterest,
308✔
NEW
71
        ];
308✔
NEW
72
        $params = array_merge($params, $context);
308✔
73

NEW
74
        $url = $this->router->generate('progressive_image_filter', array_filter($params), UrlGeneratorInterface::ABSOLUTE_URL);
308✔
75

76
        return $this->uriSigner->sign($url);
308✔
77
    }
78

79
    private function isWebpSupported(): bool
80
    {
NEW
81
        $request = $this->requestStack->getCurrentRequest();
350✔
NEW
82
        if (null === $request) {
350✔
NEW
83
            return false;
350✔
84
        }
85

NEW
86
        return false !== mb_stripos($request->headers->get('accept', ''), 'image/webp');
14✔
87
    }
88
}
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