Deprecated: Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 58

Deprecated: Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 76
Symfony Profiler

vendor/liip/imagine-bundle/DependencyInjection/Compiler/AssetsVersionCompilerPass.php line 34

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the `liip/LiipImagineBundle` project.
  4.  *
  5.  * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE.md
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Liip\ImagineBundle\DependencyInjection\Compiler;
  11. use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. /**
  14.  * Inject the Symfony framework assets version parameter to the
  15.  * LiipImagineBundle twig extension if possible.
  16.  *
  17.  * We extract the version parameter from the StaticVersionStrategy service
  18.  * definition. If anything is not as expected, we log a warning and do nothing.
  19.  *
  20.  * The expectation is for the user to configure the assets version in liip
  21.  * imagine for custom setups.
  22.  *
  23.  * Anything other than StaticVersionStrategy needs to be implemented by the
  24.  * user in CacheResolveEvent event listeners.
  25.  */
  26. class AssetsVersionCompilerPass extends AbstractCompilerPass
  27. {
  28.     public function process(ContainerBuilder $container): void
  29.     {
  30.         if (!class_exists(StaticVersionStrategy::class)
  31.             // this application has no asset version configured
  32.             || !$container->has('assets._version__default')
  33.             // we are not using the new LazyFilterRuntime
  34.             || !$container->hasDefinition('liip_imagine.templating.filter_runtime')
  35.         ) {
  36.             return;
  37.         }
  38.         $runtimeDefinition $container->getDefinition('liip_imagine.templating.filter_runtime');
  39.         if (null !== $runtimeDefinition->getArgument(1)) {
  40.             // the asset version has been set explicitly
  41.             return;
  42.         }
  43.         $versionStrategyDefinition $container->findDefinition('assets._version__default');
  44.         if (!is_a($versionStrategyDefinition->getClass(), StaticVersionStrategy::class, true)) {
  45.             $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');
  46.             return;
  47.         }
  48.         $version $versionStrategyDefinition->getArgument(0);
  49.         $format $versionStrategyDefinition->getArgument(1);
  50.         $format $container->resolveEnvPlaceholders($format);
  51.         if ($format && !$this->str_ends_with($format'?%%s')) {
  52.             $this->log($container'Can not handle assets versioning with custom format "'.$format.'". asset twig function can likely not be used with the imagine_filter');
  53.             return;
  54.         }
  55.         $runtimeDefinition->setArgument(1$version);
  56.     }
  57.     /**
  58.      * Can be replaced with the built-in method when dropping support for PHP < 8.0
  59.      */
  60.     private function str_ends_with(string $haystackstring $needle): bool
  61.     {
  62.         return mb_substr($haystack, -mb_strlen($needle)) === $needle;
  63.     }
  64. }