|
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\DependencyInjection\Compiler\CompilerPassInterface; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* For transitioning from Symfony 4 to Symfony 5 with the removal |
|
19
|
|
|
* of the kernel.root_dir parameter. |
|
20
|
|
|
*/ |
|
21
|
|
|
class NonFunctionalFilterExceptionPass implements CompilerPassInterface |
|
22
|
|
|
{ |
|
23
|
|
|
public function process(ContainerBuilder $container) |
|
24
|
|
|
{ |
|
25
|
|
|
$canFiltersStillFunction = $container->hasParameter('kernel.root_dir'); |
|
26
|
|
|
$throwWarning = function (string $filterName) use ($canFiltersStillFunction) { |
|
27
|
|
|
$message = sprintf( |
|
28
|
|
|
'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%%".', |
|
29
|
|
|
$filterName, |
|
30
|
|
|
$canFiltersStillFunction ? 'is deprecated and will not work' : 'no longer works', |
|
31
|
|
|
$filterName |
|
32
|
|
|
); |
|
33
|
|
|
|
|
34
|
|
|
if ($canFiltersStillFunction) { |
|
35
|
|
|
@trigger_error($message, E_USER_DEPRECATED); |
|
|
|
|
|
|
36
|
|
|
} else { |
|
37
|
|
|
throw new \InvalidArgumentException($message); |
|
38
|
|
|
} |
|
39
|
|
|
}; |
|
40
|
|
|
|
|
41
|
|
|
$filterSets = $container->getParameter('liip_imagine.filter_sets'); |
|
42
|
|
|
foreach ($filterSets as $filterSet) { |
|
43
|
|
|
foreach ($filterSet['filters'] as $filterName => $filter) { |
|
44
|
|
|
if ('paste' === $filterName) { |
|
45
|
|
|
$throwWarning('paste'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
if ('watermark' === $filterName) { |
|
49
|
|
|
$throwWarning('watermark'); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
// remove the definitions entirely if kernel.root_dir does not exist |
|
55
|
|
|
if (!$canFiltersStillFunction) { |
|
56
|
|
|
$container->removeDefinition('liip_imagine.filter.loader.watermark'); |
|
57
|
|
|
$container->removeDefinition('liip_imagine.filter.loader.paste'); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: