vendor/liip/imagine-bundle/DependencyInjection/Compiler/NonFunctionalFilterExceptionPass.php line 49

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\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. /**
  14.  * For transitioning from Symfony 4 to Symfony 5 with the removal
  15.  * of the kernel.root_dir parameter.
  16.  */
  17. class NonFunctionalFilterExceptionPass implements CompilerPassInterface
  18. {
  19.     public function process(ContainerBuilder $container)
  20.     {
  21.         $canFiltersStillFunction $container->hasParameter('kernel.root_dir');
  22.         $throwWarning = function (string $filterName) use ($canFiltersStillFunction) {
  23.             $message sprintf(
  24.                 'The "%s" filter %s in Symfony 5.0. Please use "%s_image" and adapt the "image" option to be relative to the "%%kernel.project_dir%%" instead of "%%kernel.root_dir%%".',
  25.                 $filterName,
  26.                 $canFiltersStillFunction 'is deprecated and will not work' 'no longer works',
  27.                 $filterName
  28.             );
  29.             if ($canFiltersStillFunction) {
  30.                 @trigger_error($messageE_USER_DEPRECATED);
  31.             } else {
  32.                 throw new \InvalidArgumentException($message);
  33.             }
  34.         };
  35.         $filterSets $container->getParameter('liip_imagine.filter_sets');
  36.         foreach ($filterSets as $filterSet) {
  37.             foreach ($filterSet['filters'] as $filterName => $filter) {
  38.                 if ('paste' === $filterName) {
  39.                     $throwWarning('paste');
  40.                 }
  41.                 if ('watermark' === $filterName) {
  42.                     $throwWarning('watermark');
  43.                 }
  44.             }
  45.         }
  46.         // remove the definitions entirely if kernel.root_dir does not exist
  47.         if (!$canFiltersStillFunction) {
  48.             $container->removeDefinition('liip_imagine.filter.loader.watermark');
  49.             $container->removeDefinition('liip_imagine.filter.loader.paste');
  50.         }
  51.     }
  52. }