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

tito10047 / progressive-image-bundle / 20991933837

14 Jan 2026 11:07AM UTC coverage: 90.185%. Remained the same
20991933837

push

github

tito10047
add changelog section with link to CHANGELOG.md in README

781 of 866 relevant lines covered (90.18%)

249.26 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
    }
406✔
37

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

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

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

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

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

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

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

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

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