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

tito10047 / progressive-image-bundle / 20675431244

03 Jan 2026 09:29AM UTC coverage: 88.617% (+0.3%) from 88.338%
20675431244

push

github

tito10047
add TTL support for image caching: implement configurable TTL handling in cache services, adapt Twig components, and update tests to validate TTL functionality

12 of 12 new or added lines in 3 files covered. (100.0%)

120 existing lines in 9 files now uncovered.

615 of 694 relevant lines covered (88.62%)

184.23 hits per line

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

65.38
/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
    ) {
UNCOV
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 {
UNCOV
53
        $path = PathHelper::urlPathToFilePath($path);
70✔
54

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

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

UNCOV
67
        $this->filterConfiguration->set($filterName, $config);
70✔
68

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

UNCOV
73
        return $this->createRedirectResponse(function () use ($path, $filterName) {
70✔
UNCOV
74
            return $this->filterService->getUrlOfFilteredImage($path, $filterName);
70✔
UNCOV
75
        }, $path, $filterName);
70✔
76
    }
77

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

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