vendor/sensio/framework-extra-bundle/src/DependencyInjection/SensioFrameworkExtraExtension.php line 41

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Sensio\Bundle\FrameworkExtraBundle\DependencyInjection;
  11. use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface;
  12. use Symfony\Component\Config\FileLocator;
  13. use Symfony\Component\Config\Resource\ClassExistenceResource;
  14. use Symfony\Component\DependencyInjection\Alias;
  15. use Symfony\Component\DependencyInjection\ContainerBuilder;
  16. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  17. use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
  18. use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  19. use Symfony\Component\HttpKernel\Kernel;
  20. use Symfony\Component\Security\Core\Authorization\ExpressionLanguage as SecurityExpressionLanguage;
  21. /**
  22.  * @author Fabien Potencier <fabien@symfony.com>
  23.  */
  24. class SensioFrameworkExtraExtension extends Extension
  25. {
  26.     public function load(array $configsContainerBuilder $container)
  27.     {
  28.         $configuration $this->getConfiguration($configs$container);
  29.         $config $this->processConfiguration($configuration$configs);
  30.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
  31.         $annotationsToLoad = [];
  32.         $definitionsToRemove = [];
  33.         if ($config['router']['annotations']) {
  34.             @trigger_error(sprintf('Enabling the "sensio_framework_extra.router.annotations" configuration is deprecated since version 5.2. Set it to false and use the "%s" annotation from Symfony itself.'\Symfony\Component\Routing\Annotation\Route::class), \E_USER_DEPRECATED);
  35.             if (Kernel::MAJOR_VERSION 5) {
  36.                 $annotationsToLoad[] = 'routing-4.4.xml';
  37.             } else {
  38.                 $annotationsToLoad[] = 'routing.xml';
  39.             }
  40.         }
  41.         if ($config['request']['converters']) {
  42.             $annotationsToLoad[] = 'converters.xml';
  43.             $container->registerForAutoconfiguration(ParamConverterInterface::class)
  44.                 ->addTag('request.param_converter');
  45.             $container->setParameter('sensio_framework_extra.disabled_converters'\is_string($config['request']['disable']) ? implode(','$config['request']['disable']) : $config['request']['disable']);
  46.             $container->addResource(new ClassExistenceResource(ExpressionLanguage::class));
  47.             if (class_exists(ExpressionLanguage::class)) {
  48.                 $container->setAlias('sensio_framework_extra.converter.doctrine.orm.expression_language', new Alias('sensio_framework_extra.converter.doctrine.orm.expression_language.default'false));
  49.             } else {
  50.                 $definitionsToRemove[] = 'sensio_framework_extra.converter.doctrine.orm.expression_language.default';
  51.             }
  52.         }
  53.         if ($config['view']['annotations']) {
  54.             $annotationsToLoad[] = 'view.xml';
  55.         }
  56.         if ($config['cache']['annotations']) {
  57.             $annotationsToLoad[] = 'cache.xml';
  58.         }
  59.         if ($config['security']['annotations']) {
  60.             $annotationsToLoad[] = 'security.xml';
  61.             $container->addResource(new ClassExistenceResource(ExpressionLanguage::class));
  62.             if (class_exists(ExpressionLanguage::class)) {
  63.                 // this resource can only be added if ExpressionLanguage exists (to avoid a fatal error)
  64.                 $container->addResource(new ClassExistenceResource(SecurityExpressionLanguage::class));
  65.                 if (class_exists(SecurityExpressionLanguage::class)) {
  66.                     $container->setAlias('sensio_framework_extra.security.expression_language', new Alias($config['security']['expression_language'], false));
  67.                 } else {
  68.                     $definitionsToRemove[] = 'sensio_framework_extra.security.expression_language.default';
  69.                 }
  70.             } else {
  71.                 $definitionsToRemove[] = 'sensio_framework_extra.security.expression_language.default';
  72.             }
  73.         }
  74.         if ($annotationsToLoad) {
  75.             // must be first
  76.             $loader->load('annotations.xml');
  77.             foreach ($annotationsToLoad as $configFile) {
  78.                 $loader->load($configFile);
  79.             }
  80.             if ($config['request']['converters']) {
  81.                 $container->getDefinition('sensio_framework_extra.converter.listener')->replaceArgument(1$config['request']['auto_convert']);
  82.             }
  83.         }
  84.         if (!empty($config['templating']['controller_patterns'])) {
  85.             $container
  86.                 ->getDefinition('sensio_framework_extra.view.guesser')
  87.                 ->addArgument($config['templating']['controller_patterns']);
  88.         }
  89.         foreach ($definitionsToRemove as $definition) {
  90.             $container->removeDefinition($definition);
  91.         }
  92.     }
  93.     /**
  94.      * Returns the base path for the XSD files.
  95.      *
  96.      * @return string The XSD base path
  97.      */
  98.     public function getXsdValidationBasePath()
  99.     {
  100.         return __DIR__.'/../Resources/config/schema';
  101.     }
  102.     /**
  103.      * @return string
  104.      */
  105.     public function getNamespace()
  106.     {
  107.         return 'http://symfony.com/schema/dic/symfony_extra';
  108.     }
  109. }