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 Psr\Http\Message\StreamFactoryInterface;
  12. use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface;
  13. use Symfony\Component\Config\FileLocator;
  14. use Symfony\Component\Config\Resource\ClassExistenceResource;
  15. use Symfony\Component\DependencyInjection\Alias;
  16. use Symfony\Component\DependencyInjection\ContainerBuilder;
  17. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  18. use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
  19. use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  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.             $annotationsToLoad[] = 'routing.xml';
  36.         }
  37.         if ($config['request']['converters']) {
  38.             $annotationsToLoad[] = 'converters.xml';
  39.             $container->registerForAutoconfiguration(ParamConverterInterface::class)
  40.                 ->addTag('request.param_converter');
  41.             $container->setParameter('sensio_framework_extra.disabled_converters', \is_string($config['request']['disable']) ? implode(','$config['request']['disable']) : $config['request']['disable']);
  42.             $container->addResource(new ClassExistenceResource(ExpressionLanguage::class));
  43.             if (class_exists(ExpressionLanguage::class)) {
  44.                 $container->setAlias('sensio_framework_extra.converter.doctrine.orm.expression_language', new Alias('sensio_framework_extra.converter.doctrine.orm.expression_language.default'false));
  45.             } else {
  46.                 $definitionsToRemove[] = 'sensio_framework_extra.converter.doctrine.orm.expression_language.default';
  47.             }
  48.         }
  49.         if ($config['view']['annotations']) {
  50.             $annotationsToLoad[] = 'view.xml';
  51.         }
  52.         if ($config['cache']['annotations']) {
  53.             $annotationsToLoad[] = 'cache.xml';
  54.         }
  55.         if ($config['security']['annotations']) {
  56.             $annotationsToLoad[] = 'security.xml';
  57.             $container->addResource(new ClassExistenceResource(ExpressionLanguage::class));
  58.             if (class_exists(ExpressionLanguage::class)) {
  59.                 // this resource can only be added if ExpressionLanguage exists (to avoid a fatal error)
  60.                 $container->addResource(new ClassExistenceResource(SecurityExpressionLanguage::class));
  61.                 if (class_exists(SecurityExpressionLanguage::class)) {
  62.                     $container->setAlias('sensio_framework_extra.security.expression_language', new Alias($config['security']['expression_language'], false));
  63.                 } else {
  64.                     $definitionsToRemove[] = 'sensio_framework_extra.security.expression_language.default';
  65.                 }
  66.             } else {
  67.                 $definitionsToRemove[] = 'sensio_framework_extra.security.expression_language.default';
  68.             }
  69.         }
  70.         if ($annotationsToLoad) {
  71.             // must be first
  72.             $loader->load('annotations.xml');
  73.             foreach ($annotationsToLoad as $configFile) {
  74.                 $loader->load($configFile);
  75.             }
  76.             if ($config['request']['converters']) {
  77.                 $container->getDefinition('sensio_framework_extra.converter.listener')->replaceArgument(1$config['request']['auto_convert']);
  78.             }
  79.         }
  80.         if (!empty($config['templating']['controller_patterns'])) {
  81.             $container
  82.                 ->getDefinition('sensio_framework_extra.view.guesser')
  83.                 ->addArgument($config['templating']['controller_patterns']);
  84.         }
  85.         if ($config['psr_message']['enabled']) {
  86.             $loader->load('psr7.xml');
  87.             if (!interface_exists(StreamFactoryInterface::class)) {
  88.                 $definitionsToRemove[] = 'sensio_framework_extra.psr7.argument_value_resolver.server_request';
  89.             }
  90.         }
  91.         foreach ($definitionsToRemove as $definition) {
  92.             $container->removeDefinition($definition);
  93.         }
  94.     }
  95.     /**
  96.      * Returns the base path for the XSD files.
  97.      *
  98.      * @return string The XSD base path
  99.      */
  100.     public function getXsdValidationBasePath()
  101.     {
  102.         return __DIR__.'/../Resources/config/schema';
  103.     }
  104.     public function getNamespace()
  105.     {
  106.         return 'http://symfony.com/schema/dic/symfony_extra';
  107.     }
  108. }