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

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <[email protected]>
  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 <[email protected]>
  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.             if (\PHP_VERSION_ID 70000) {
  37.                 $this->addClassesToCompile([
  38.                     'Sensio\\Bundle\\FrameworkExtraBundle\\EventListener\\ControllerListener',
  39.                 ]);
  40.             }
  41.         }
  42.         if ($config['request']['converters']) {
  43.             $annotationsToLoad[] = 'converters.xml';
  44.             $container->registerForAutoconfiguration(ParamConverterInterface::class)
  45.                 ->addTag('request.param_converter');
  46.             $container->setParameter('sensio_framework_extra.disabled_converters', \is_string($config['request']['disable']) ? implode(','$config['request']['disable']) : $config['request']['disable']);
  47.             $container->addResource(new ClassExistenceResource(ExpressionLanguage::class));
  48.             if (class_exists(ExpressionLanguage::class)) {
  49.                 $container->setAlias('sensio_framework_extra.converter.doctrine.orm.expression_language', new Alias('sensio_framework_extra.converter.doctrine.orm.expression_language.default'false));
  50.             } else {
  51.                 $definitionsToRemove[] = 'sensio_framework_extra.converter.doctrine.orm.expression_language.default';
  52.             }
  53.             if (\PHP_VERSION_ID 70000) {
  54.                 $this->addClassesToCompile([
  55.                     // cannot be added because it has some annotations
  56.                     //'Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\ParamConverter',
  57.                     'Sensio\\Bundle\\FrameworkExtraBundle\\EventListener\\ParamConverterListener',
  58.                     'Sensio\\Bundle\\FrameworkExtraBundle\\Request\\ParamConverter\\DateTimeParamConverter',
  59.                     'Sensio\\Bundle\\FrameworkExtraBundle\\Request\\ParamConverter\\DoctrineParamConverter',
  60.                     'Sensio\\Bundle\\FrameworkExtraBundle\\Request\\ParamConverter\\ParamConverterInterface',
  61.                     'Sensio\\Bundle\\FrameworkExtraBundle\\Request\\ParamConverter\\ParamConverterManager',
  62.                 ]);
  63.             }
  64.         }
  65.         if ($config['view']['annotations']) {
  66.             $annotationsToLoad[] = 'view.xml';
  67.             if (\PHP_VERSION_ID 70000) {
  68.                 $this->addClassesToCompile([
  69.                     'Sensio\\Bundle\\FrameworkExtraBundle\\EventListener\\TemplateListener',
  70.                 ]);
  71.             }
  72.         }
  73.         if ($config['cache']['annotations']) {
  74.             $annotationsToLoad[] = 'cache.xml';
  75.             if (\PHP_VERSION_ID 70000) {
  76.                 $this->addClassesToCompile([
  77.                     'Sensio\\Bundle\\FrameworkExtraBundle\\EventListener\\HttpCacheListener',
  78.                 ]);
  79.             }
  80.         }
  81.         if ($config['security']['annotations']) {
  82.             $annotationsToLoad[] = 'security.xml';
  83.             $container->addResource(new ClassExistenceResource(ExpressionLanguage::class));
  84.             if (class_exists(ExpressionLanguage::class)) {
  85.                 // this resource can only be added if ExpressionLanguage exists (to avoid a fatal error)
  86.                 $container->addResource(new ClassExistenceResource(SecurityExpressionLanguage::class));
  87.                 if (class_exists(SecurityExpressionLanguage::class)) {
  88.                     $container->setAlias('sensio_framework_extra.security.expression_language', new Alias($config['security']['expression_language'], false));
  89.                 } else {
  90.                     $definitionsToRemove[] = 'sensio_framework_extra.security.expression_language.default';
  91.                 }
  92.             } else {
  93.                 $definitionsToRemove[] = 'sensio_framework_extra.security.expression_language.default';
  94.             }
  95.             if (\PHP_VERSION_ID 70000) {
  96.                 $this->addClassesToCompile([
  97.                     'Sensio\\Bundle\\FrameworkExtraBundle\\EventListener\\SecurityListener',
  98.                 ]);
  99.             }
  100.         }
  101.         if ($annotationsToLoad) {
  102.             // must be first
  103.             $loader->load('annotations.xml');
  104.             foreach ($annotationsToLoad as $configFile) {
  105.                 $loader->load($configFile);
  106.             }
  107.             if (\PHP_VERSION_ID 70000) {
  108.                 $this->addClassesToCompile([
  109.                     'Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\ConfigurationAnnotation',
  110.                 ]);
  111.             }
  112.             if ($config['request']['converters']) {
  113.                 $container->getDefinition('sensio_framework_extra.converter.listener')->replaceArgument(1$config['request']['auto_convert']);
  114.             }
  115.         }
  116.         if (!empty($config['templating']['controller_patterns'])) {
  117.             $container
  118.                 ->getDefinition('sensio_framework_extra.view.guesser')
  119.                 ->addArgument($config['templating']['controller_patterns']);
  120.         }
  121.         if ($config['psr_message']['enabled']) {
  122.             $loader->load('psr7.xml');
  123.             if (!interface_exists(StreamFactoryInterface::class)) {
  124.                 $definitionsToRemove[] = 'sensio_framework_extra.psr7.argument_value_resolver.server_request';
  125.             }
  126.         }
  127.         foreach ($definitionsToRemove as $definition) {
  128.             $container->removeDefinition($definition);
  129.         }
  130.     }
  131.     /**
  132.      * Returns the base path for the XSD files.
  133.      *
  134.      * @return string The XSD base path
  135.      */
  136.     public function getXsdValidationBasePath()
  137.     {
  138.         return __DIR__.'/../Resources/config/schema';
  139.     }
  140.     public function getNamespace()
  141.     {
  142.         return 'http://symfony.com/schema/dic/symfony_extra';
  143.     }
  144. }