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

tito10047 / progressive-image-bundle / 20894678042

11 Jan 2026 11:52AM UTC coverage: 89.9% (-0.08%) from 89.975%
20894678042

push

github

tito10047
Add support for custom filter in LiipImagineControllerTest and ResponsiveAttributeGeneratorTest

2 of 9 new or added lines in 3 files covered. (22.22%)

139 existing lines in 9 files now uncovered.

721 of 802 relevant lines covered (89.9%)

261.42 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
    ) {
UNCOV
36
    }
406✔
37

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

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

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

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

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

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

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

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

UNCOV
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