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

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\Security\Core\Authorization\ExpressionLanguage as SecurityExpressionLanguage;
  20. /**
  21.  * @author Fabien Potencier <fabien@symfony.com>
  22.  */
  23. class SensioFrameworkExtraExtension extends Extension
  24. {
  25.     public function load(array $configsContainerBuilder $container)
  26.     {
  27.         $configuration $this->getConfiguration($configs$container);
  28.         $config $this->processConfiguration($configuration$configs);
  29.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
  30.         $annotationsToLoad = [];
  31.         $definitionsToRemove = [];
  32.         if ($config['router']['annotations']) {
  33.             @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);
  34.             $annotationsToLoad[] = 'routing.xml';
  35.         }
  36.         if ($config['request']['converters']) {
  37.             $annotationsToLoad[] = 'converters.xml';
  38.             $container->registerForAutoconfiguration(ParamConverterInterface::class)
  39.                 ->addTag('request.param_converter');
  40.             $container->setParameter('sensio_framework_extra.disabled_converters', \is_string($config['request']['disable']) ? implode(','$config['request']['disable']) : $config['request']['disable']);
  41.             $container->addResource(new ClassExistenceResource(ExpressionLanguage::class));
  42.             if (class_exists(ExpressionLanguage::class)) {
  43.                 $container->setAlias('sensio_framework_extra.converter.doctrine.orm.expression_language', new Alias('sensio_framework_extra.converter.doctrine.orm.expression_language.default'false));
  44.             } else {
  45.                 $definitionsToRemove[] = 'sensio_framework_extra.converter.doctrine.orm.expression_language.default';
  46.             }
  47.         }
  48.         if ($config['view']['annotations']) {
  49.             $annotationsToLoad[] = 'view.xml';
  50.         }
  51.         if ($config['cache']['annotations']) {
  52.             $annotationsToLoad[] = 'cache.xml';
  53.         }
  54.         if ($config['security']['annotations']) {
  55.             $annotationsToLoad[] = 'security.xml';
  56.             $container->addResource(new ClassExistenceResource(ExpressionLanguage::class));
  57.             if (class_exists(ExpressionLanguage::class)) {
  58.                 // this resource can only be added if ExpressionLanguage exists (to avoid a fatal error)
  59.                 $container->addResource(new ClassExistenceResource(SecurityExpressionLanguage::class));
  60.                 if (class_exists(SecurityExpressionLanguage::class)) {
  61.                     $container->setAlias('sensio_framework_extra.security.expression_language', new Alias($config['security']['expression_language'], false));
  62.                 } else {
  63.                     $definitionsToRemove[] = 'sensio_framework_extra.security.expression_language.default';
  64.                 }
  65.             } else {
  66.                 $definitionsToRemove[] = 'sensio_framework_extra.security.expression_language.default';
  67.             }
  68.         }
  69.         if ($annotationsToLoad) {
  70.             // must be first
  71.             $loader->load('annotations.xml');
  72.             foreach ($annotationsToLoad as $configFile) {
  73.                 $loader->load($configFile);
  74.             }
  75.             if ($config['request']['converters']) {
  76.                 $container->getDefinition('sensio_framework_extra.converter.listener')->replaceArgument(1$config['request']['auto_convert']);
  77.             }
  78.         }
  79.         if (!empty($config['templating']['controller_patterns'])) {
  80.             $container
  81.                 ->getDefinition('sensio_framework_extra.view.guesser')
  82.                 ->addArgument($config['templating']['controller_patterns']);
  83.         }
  84.         foreach ($definitionsToRemove as $definition) {
  85.             $container->removeDefinition($definition);
  86.         }
  87.     }
  88.     /**
  89.      * Returns the base path for the XSD files.
  90.      *
  91.      * @return string The XSD base path
  92.      */
  93.     public function getXsdValidationBasePath()
  94.     {
  95.         return __DIR__.'/../Resources/config/schema';
  96.     }
  97.     public function getNamespace()
  98.     {
  99.         return 'http://symfony.com/schema/dic/symfony_extra';
  100.     }
  101. }