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

tito10047 / progressive-image-bundle / 21092461285

17 Jan 2026 09:56AM UTC coverage: 90.889% (+0.5%) from 90.395%
21092461285

push

github

web-flow
Merge pull request #3 from tito10047/modifiers

add modifiers capability

42 of 55 new or added lines in 10 files covered. (76.36%)

1 existing line in 1 file now uncovered.

838 of 922 relevant lines covered (90.89%)

308.03 hits per line

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

73.53
/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 Tito10047\ProgressiveImageBundle\Service\LiipImagineRuntimeConfigGeneratorInterface;
30
use Tito10047\ProgressiveImageBundle\Service\MetadataReaderInterface;
31

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

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

NEW
55
                $context = $request->query->all();
140✔
NEW
56
                unset($context['path'], $context['width'], $context['height'], $context['filter'], $context['pointInterest'], $context['_hash']);
140✔
57

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

NEW
66
                $result = $this->runtimeConfigGenerator->generate($width, $height, $filter, $pointInterest, $origWidth, $origHeight, $context);
140✔
67
        $filterName = $result['filterName'];
140✔
68
        $config = $result['config'];
140✔
69

70
        $this->filterConfiguration->set($filterName, $config);
140✔
71

72
        if (true !== $this->signer->checkRequest($request)) {
140✔
73
            throw new BadRequestHttpException(\sprintf('Signed url does not pass the sign check for path "%s" and filter "%s"', $path, $filter));
×
74
        }
75

76
                return $this->createRedirectResponse(function () use ($path, $filterName, $request) {
140✔
77
                        return $this->filterService->getUrlOfFilteredImage(
140✔
78
                                $path,
140✔
79
                                $filterName,
140✔
80
                                null,
140✔
81
                                $this->isWebpSupported($request)
140✔
82
                        );
140✔
83
        }, $path, $filterName);
140✔
84
    }
85

86
        private function isWebpSupported(Request $request): bool {
87
                return false !== mb_stripos($request->headers->get('accept', ''), 'image/webp');
140✔
88
        }
89

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

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