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

tito10047 / progressive-image-bundle / 20675022582

03 Jan 2026 08:51AM UTC coverage: 86.782%. Remained the same
20675022582

push

github

tito10047
update copyright in LICENSE.md

604 of 696 relevant lines covered (86.78%)

175.71 hits per line

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

64.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 Tito10047\ProgressiveImageBundle\Service\LiipImagineRuntimeConfigGeneratorInterface;
16
use Tito10047\ProgressiveImageBundle\Service\MetadataReaderInterface;
17
use Liip\ImagineBundle\Config\Controller\ControllerConfig;
18
use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException;
19
use Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException;
20
use Liip\ImagineBundle\Imagine\Cache\Helper\PathHelper;
21
use Liip\ImagineBundle\Imagine\Data\DataManager;
22
use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration;
23
use Liip\ImagineBundle\Service\FilterService;
24
use Symfony\Component\HttpFoundation\RedirectResponse;
25
use Symfony\Component\HttpFoundation\Request;
26
use Symfony\Component\HttpFoundation\Response;
27
use Symfony\Component\HttpFoundation\UriSigner;
28
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
29
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
30
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
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
        }
70✔
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);
70✔
54

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

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

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

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

75
                return $this->createRedirectResponse(function () use ($path, $filterName, $request) {
70✔
76
                        return $this->filterService->getUrlOfFilteredImage($path, $filterName);
70✔
77
                }, $path, $filterName);
70✔
78
        }
79

80
        private function createRedirectResponse(\Closure $url, string $path, string $filter): RedirectResponse
81
        {
82
                try {
83
                        return new RedirectResponse($url(), $this->controllerConfig->getRedirectResponseCode());
70✔
84
                } catch (NotLoadableException $exception) {
×
85
                        if (null !== $this->dataManager->getDefaultImageUrl($filter)) {
×
86
                                return new RedirectResponse($this->dataManager->getDefaultImageUrl($filter));
×
87
                        }
88

89
                        throw new NotFoundHttpException(\sprintf('Source image for path "%s" could not be found', $path), $exception);
×
90
                } catch (NonExistingFilterException $exception) {
×
91
                        throw new NotFoundHttpException(\sprintf('Requested non-existing filter "%s"', $filter), $exception);
×
92
                } catch (\RuntimeException $exception) {
×
93
                        throw new \RuntimeException(\sprintf('Unable to create image for path "%s" and filter "%s". Message was "%s"', $path, $filter, $exception->getMessage()), 0, $exception);
×
94
                }
95
        }
96

97
        private function isWebpSupported(Request $request): bool
98
        {
99
                return false !== mb_stripos($request->headers->get('accept', ''), 'image/webp');
×
100
        }
101
}
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