vendor/symfony-cmf/routing-bundle/src/DependencyInjection/Configuration.php line 37

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony CMF package.
  4.  *
  5.  * (c) Symfony CMF
  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 Symfony\Cmf\Bundle\RoutingBundle\DependencyInjection;
  11. use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\Route;
  12. use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
  13. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  14. use Symfony\Component\Config\Definition\ConfigurationInterface;
  15. /**
  16.  * This class contains the configuration information for the bundle.
  17.  *
  18.  * This information is solely responsible for how the different configuration
  19.  * sections are normalized, and merged.
  20.  *
  21.  * @author David Buchmann
  22.  */
  23. class Configuration implements ConfigurationInterface
  24. {
  25.     /**
  26.      * Returns the config tree builder.
  27.      *
  28.      * @return TreeBuilder
  29.      */
  30.     public function getConfigTreeBuilder()
  31.     {
  32.         $treeBuilder = new TreeBuilder();
  33.         $root $treeBuilder->root('cmf_routing');
  34.         $this->addChainSection($root);
  35.         $this->addDynamicSection($root);
  36.         return $treeBuilder;
  37.     }
  38.     private function addChainSection(ArrayNodeDefinition $root)
  39.     {
  40.         $root
  41.             ->children()
  42.                 ->arrayNode('chain')
  43.                     ->addDefaultsIfNotSet()
  44.                     ->fixXmlConfig('router_by_id''routers_by_id')
  45.                     ->children()
  46.                         ->arrayNode('routers_by_id')
  47.                             ->defaultValue(['router.default' => 100])
  48.                             ->useAttributeAsKey('id')
  49.                             ->prototype('scalar')->end()
  50.                         ->end() // routers_by_id
  51.                         ->booleanNode('replace_symfony_router')->defaultTrue()->end()
  52.                     ->end()
  53.                 ->end()// chain
  54.             ->end()
  55.         ;
  56.     }
  57.     private function addDynamicSection(ArrayNodeDefinition $root)
  58.     {
  59.         $root
  60.             ->children()
  61.                 ->arrayNode('dynamic')
  62.                     ->fixXmlConfig('controller_by_type''controllers_by_type')
  63.                     ->fixXmlConfig('controller_by_class''controllers_by_class')
  64.                     ->fixXmlConfig('template_by_class''templates_by_class')
  65.                     ->fixXmlConfig('route_filter_by_id''route_filters_by_id')
  66.                     ->fixXmlConfig('locale')
  67.                     ->addDefaultsIfNotSet()
  68.                     ->canBeEnabled()
  69.                     ->children()
  70.                         ->scalarNode('route_collection_limit')->defaultValue(0)->end()
  71.                         ->scalarNode('generic_controller')->defaultNull()->end()
  72.                         ->scalarNode('default_controller')->defaultNull()->end()
  73.                         ->arrayNode('controllers_by_type')
  74.                             ->useAttributeAsKey('type')
  75.                             ->prototype('scalar')->end()
  76.                         ->end() // controllers_by_type
  77.                         ->arrayNode('controllers_by_class')
  78.                             ->useAttributeAsKey('class')
  79.                             ->prototype('scalar')->end()
  80.                         ->end() // controllers_by_class
  81.                         ->arrayNode('templates_by_class')
  82.                             ->useAttributeAsKey('class')
  83.                             ->prototype('scalar')->end()
  84.                         ->end() // templates_by_class
  85.                         ->arrayNode('persistence')
  86.                             ->addDefaultsIfNotSet()
  87.                             ->validate()
  88.                                 ->ifTrue(function ($v) {
  89.                                     return count(array_filter($v, function ($persistence) {
  90.                                         return $persistence['enabled'];
  91.                                     })) > 1;
  92.                                 })
  93.                                 ->thenInvalid('Only one persistence layer can be enabled at the same time.')
  94.                             ->end()
  95.                             ->children()
  96.                                 ->arrayNode('phpcr')
  97.                                     ->addDefaultsIfNotSet()
  98.                                     ->canBeEnabled()
  99.                                     ->fixXmlConfig('route_basepath')
  100.                                     ->children()
  101.                                         ->scalarNode('manager_name')->defaultNull()->end()
  102.                                         ->arrayNode('route_basepaths')
  103.                                             ->beforeNormalization()
  104.                                                 ->ifString()
  105.                                                 ->then(function ($v) {
  106.                                                     return [$v];
  107.                                                 })
  108.                                             ->end()
  109.                                             ->prototype('scalar')->end()
  110.                                             ->defaultValue(['/cms/routes'])
  111.                                         ->end() // route_basepaths
  112.                                         ->booleanNode('enable_initializer')
  113.                                             ->defaultValue(true)
  114.                                         ->end()
  115.                                     ->end()
  116.                                 ->end() // phpcr
  117.                                 ->arrayNode('orm')
  118.                                     ->addDefaultsIfNotSet()
  119.                                     ->canBeEnabled()
  120.                                     ->children()
  121.                                         ->scalarNode('manager_name')->defaultNull()->end()
  122.                                         ->scalarNode('route_class')->defaultValue(Route::class)->end()
  123.                                     ->end()
  124.                                 ->end() // orm
  125.                             ->end()
  126.                         ->end() // persistence
  127.                         ->scalarNode('uri_filter_regexp')->defaultValue('')->end()
  128.                         ->scalarNode('route_provider_service_id')->end()
  129.                         ->arrayNode('route_filters_by_id')
  130.                             ->canBeUnset()
  131.                             ->defaultValue([])
  132.                             ->useAttributeAsKey('id')
  133.                             ->prototype('scalar')->end()
  134.                         ->end() // route_filters_by_id
  135.                         ->scalarNode('content_repository_service_id')->end()
  136.                         ->arrayNode('locales')
  137.                             ->prototype('scalar')->end()
  138.                         ->end() // locales
  139.                         ->integerNode('limit_candidates')->defaultValue(20)->end()
  140.                         ->booleanNode('match_implicit_locale')->defaultValue(true)->end()
  141.                         ->booleanNode('auto_locale_pattern')->defaultValue(false)->end()
  142.                         ->scalarNode('url_generator')
  143.                             ->defaultValue('cmf_routing.generator')
  144.                             ->info('URL generator service ID')
  145.                         ->end() // url_generator
  146.                     ->end()
  147.                 ->end() // dynamic
  148.             ->end()
  149.         ;
  150.     }
  151. }