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

liip / LiipImagineBundle / 8050676635

26 Feb 2024 02:40PM UTC coverage: 80.511%. Remained the same
8050676635

Pull #1570

github

web-flow
Merge ce8d5dc36 into 65613e842
Pull Request #1570: 2 to 3

1764 of 2191 relevant lines covered (80.51%)

77.73 hits per line

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

0.0
/src/DependencyInjection/Compiler/AssetsVersionCompilerPass.php
1
<?php
2

3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11

12
namespace Liip\ImagineBundle\DependencyInjection\Compiler;
13

14
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16

17
/**
18
 * Inject the Symfony framework assets version parameter to the
19
 * LiipImagineBundle twig extension if possible.
20
 *
21
 * We extract the version parameter from the StaticVersionStrategy service
22
 * definition. If anything is not as expected, we log a warning and do nothing.
23
 *
24
 * The expectation is for the user to configure the assets version in liip
25
 * imagine for custom setups.
26
 *
27
 * Anything other than StaticVersionStrategy needs to be implemented by the
28
 * user in CacheResolveEvent event listeners.
29
 */
30
class AssetsVersionCompilerPass extends AbstractCompilerPass
31
{
32
    public function process(ContainerBuilder $container): void
33
    {
34
        if (!class_exists(StaticVersionStrategy::class)
×
35
            // this application has no asset version configured
36
            || !$container->has('assets._version__default')
×
37
            // we are not using the new LazyFilterRuntime
38
            || !$container->hasDefinition('liip_imagine.templating.filter_runtime')
×
39
        ) {
40
            return;
×
41
        }
42
        $runtimeDefinition = $container->getDefinition('liip_imagine.templating.filter_runtime');
×
43
        if (null !== $runtimeDefinition->getArgument(1)) {
×
44
            // the asset version has been set explicitly
45
            return;
×
46
        }
47

48
        $versionStrategyDefinition = $container->findDefinition('assets._version__default');
×
49
        if (!is_a($versionStrategyDefinition->getClass(), StaticVersionStrategy::class, true)) {
×
50
            $this->log($container, 'Symfony assets versioning strategy "'.$versionStrategyDefinition->getClass().'" not automatically supported. Configure liip_imagine.twig.assets_version if you have problems with assets versioning');
×
51

52
            return;
×
53
        }
54
        $version = $versionStrategyDefinition->getArgument(0);
×
55
        $format = $versionStrategyDefinition->getArgument(1);
×
56
        $format = $container->resolveEnvPlaceholders($format);
×
57
        if ($format && !str_ends_with($format, '?%%s')) {
×
58
            $this->log($container, 'Can not handle assets versioning with custom format "'.$format.'". asset twig function can likely not be used with the imagine_filter');
×
59

60
            return;
×
61
        }
62

63
        $runtimeDefinition->setArgument(1, $version);
×
64
    }
65
}
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

© 2025 Coveralls, Inc