| 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 |  |  |         $canFiltersStillFunction = $container->hasParameter('kernel.root_dir'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         $throwWarning = function(string $filterName) use ($canFiltersStillFunction) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |             $message = sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |                 '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%%".', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |                 $filterName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |                 $canFiltersStillFunction ? 'is deprecated and will not work' : 'no longer works', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |                 $filterName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             if ($canFiltersStillFunction) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |                 @trigger_error($message, E_USER_DEPRECATED); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                 throw new \InvalidArgumentException($message); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $filterSets = $container->getParameter('liip_imagine.filter_sets'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         foreach ($filterSets as $filterSet) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             foreach ($filterSet['filters'] as $filterName => $filter) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                 if ($filterName === 'paste') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |                     $throwWarning('paste'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                 if ($filterName === 'watermark') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                     $throwWarning('watermark'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         // remove the definitions entirely if kernel.root_dir does not exist | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         if (!$canFiltersStillFunction) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             $container->removeDefinition('liip_imagine.filter.loader.watermark'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             $container->removeDefinition('liip_imagine.filter.loader.paste'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 53 |  |  | } | 
            
                        
If you suppress an error, we recommend checking for the error condition explicitly: