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

tito10047 / progressive-image-bundle / 23349657191

20 Mar 2026 03:22PM UTC coverage: 90.385% (+0.1%) from 90.276%
23349657191

push

github

Jozef Mostka
fix path caching when custom filter is aplied

0 of 17 new or added lines in 3 files covered. (0.0%)

2 existing lines in 1 file now uncovered.

893 of 988 relevant lines covered (90.38%)

344.87 hits per line

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

74.29
/src/Controller/LiipImagineController.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\Controller;
14

15
use Liip\ImagineBundle\Config\Controller\ControllerConfig;
16
use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException;
17
use Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException;
18
use Liip\ImagineBundle\Imagine\Cache\Helper\PathHelper;
19
use Liip\ImagineBundle\Imagine\Data\DataManager;
20
use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration;
21
use Liip\ImagineBundle\Service\FilterService;
22
use Symfony\Component\HttpFoundation\RedirectResponse;
23
use Symfony\Component\HttpFoundation\Request;
24
use Symfony\Component\HttpFoundation\Response;
25
use Symfony\Component\HttpFoundation\UriSigner;
26
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
27
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
28
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
29
use Symfony\Contracts\Cache\TagAwareCacheInterface;
30
use Tito10047\ProgressiveImageBundle\Service\LiipImagineRuntimeConfigGeneratorInterface;
31
use Tito10047\ProgressiveImageBundle\Service\MetadataReaderInterface;
32

33
final class LiipImagineController
34
{
35
    public function __construct(
36
        private readonly UriSigner $signer,
37
        private readonly FilterService $filterService,
38
        private readonly DataManager $dataManager,
39
        private readonly FilterConfiguration $filterConfiguration,
40
        private readonly ControllerConfig $controllerConfig,
41
        private readonly LiipImagineRuntimeConfigGeneratorInterface $runtimeConfigGenerator,
42
        private readonly MetadataReaderInterface $metadataReader,
43
                private readonly ?TagAwareCacheInterface $cache,
44
    ) {
45
    }
154✔
46

47
    public function index(
48
        Request $request,
49
        #[MapQueryParameter] string $path,
50
        #[MapQueryParameter] int $width,
51
        #[MapQueryParameter] int $height,
52
        #[MapQueryParameter] ?string $filter = null,
53
        #[MapQueryParameter] ?string $pointInterest = null,
54
    ): Response {
55
        $path = PathHelper::urlPathToFilePath($path);
154✔
56

57
        $context = $request->query->all();
154✔
58
        unset($context['path'], $context['width'], $context['height'], $context['filter'], $context['pointInterest'], $context['_hash'], $context['_expiration']);
154✔
59

60
        $origWidth = null;
154✔
61
        $origHeight = null;
154✔
62
        if ($pointInterest) {
154✔
63
            $metadata = $this->metadataReader->getMetadata($path);
28✔
64
            $origWidth = $metadata->width;
28✔
65
            $origHeight = $metadata->height;
28✔
66
        }
67

68
        $result = $this->runtimeConfigGenerator->generate($width, $height, $filter, $pointInterest, $origWidth, $origHeight, $context);
154✔
69
        $filterName = $result['filterName'];
154✔
70
        $config = $result['config'];
154✔
71

72
        $this->filterConfiguration->set($filterName, $config);
154✔
NEW
73
                $this->cache?->invalidateTags(['pgi_tag_'.md5($path)]);
154✔
74

75
        if (true !== $this->signer->checkRequest($request) && $request->attributes->get('_route') !== null) {
154✔
76
            throw new BadRequestHttpException(\sprintf('Signed url does not pass the sign check for path "%s" and filter "%s"', $path, $filter));
×
77
        }
78

79
        return $this->createRedirectResponse(function () use ($path, $filterName, $request) {
154✔
80
            return $this->filterService->getUrlOfFilteredImage(
154✔
81
                $path,
154✔
82
                $filterName,
154✔
83
                null,
154✔
84
                $this->isWebpSupported($request)
154✔
85
            );
154✔
86
        }, $path, $filterName);
154✔
87
    }
88

89
    private function isWebpSupported(Request $request): bool
90
    {
91
        return false !== mb_stripos($request->headers->get('accept', ''), 'image/webp');
154✔
92
    }
93

94
    private function createRedirectResponse(\Closure $url, string $path, string $filter): RedirectResponse
95
    {
96
        try {
97
            return new RedirectResponse($url(), $this->controllerConfig->getRedirectResponseCode());
154✔
98
        } catch (NotLoadableException $exception) {
×
99
            if (null !== $this->dataManager->getDefaultImageUrl($filter)) {
×
100
                return new RedirectResponse($this->dataManager->getDefaultImageUrl($filter));
×
101
            }
102

103
            throw new NotFoundHttpException(\sprintf('Source image for path "%s" could not be found', $path), $exception);
×
104
        } catch (NonExistingFilterException $exception) {
×
105
            throw new NotFoundHttpException(\sprintf('Requested non-existing filter "%s"', $filter), $exception);
×
106
        } catch (\RuntimeException $exception) {
×
107
            throw new \RuntimeException(\sprintf('Unable to create image for path "%s" and filter "%s". Message was "%s"', $path, $filter, $exception->getMessage()), 0, $exception);
×
108
        }
109
    }
110
}
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