Completed
Pull Request — symfony5 (#1256)
by
unknown
09:52
created

NonFunctionalFilterExceptionPass::process()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 8.9777
c 0
b 0
f 0
cc 6
nc 6
nop 1
1
<?php
2
3
namespace Liip\ImagineBundle\DependencyInjection\Compiler;
4
5
use Liip\ImagineBundle\Imagine\Filter\Loader\NonFunctionalPasteFilterLoader;
6
use Liip\ImagineBundle\Imagine\Filter\Loader\NonFunctionalWatermarkFilterLoader;
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
10
/**
11
 * For transitioning from Symfony 4 to Symfony 5 with the removal
12
 * of the kernel.root_dir parameter.
13
 */
14
class NonFunctionalFilterExceptionPass implements CompilerPassInterface
15
{
16
    public function process(ContainerBuilder $container)
17
    {
18
        // only needed if kernel.root_dir is no longer present
19
        if ($container->hasParameter('kernel.root_dir')) {
20
            return;
21
        }
22
23
        $filterSets = $container->getParameter('liip_imagine.filter_sets');
24
        foreach ($filterSets as $filterSet) {
25
            foreach ($filterSet['filters'] as $filterName => $filter) {
26
                if ($filter === 'paste') {
27
                    throw new \InvalidArgumentException(sprintf('The "paste" filter no longer works in Symfony 5.0. Please use "paste_image" and adapt the "image" to be relative to the "%kernel.project_dir%" instead of "%kernel.root_dir%".'));
28
                }
29
30
                if ($filter === 'watermark') {
31
                    throw new \InvalidArgumentException(sprintf('The "paste" filter no longer works in Symfony 5.0. Please use "paste_image" and adapt the "image" to be relative to the "%kernel.project_dir%" instead of "%kernel.root_dir%".'));
32
                }
33
            }
34
        }
35
    }
36
}