vendor/nelmio/api-doc-bundle/DependencyInjection/Configuration.php line 38

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the NelmioApiDocBundle package.
  4.  *
  5.  * (c) Nelmio
  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 Nelmio\ApiDocBundle\DependencyInjection;
  11. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  12. use Symfony\Component\Config\Definition\ConfigurationInterface;
  13. final class Configuration implements ConfigurationInterface
  14. {
  15.     public function getConfigTreeBuilder()
  16.     {
  17.         $treeBuilder = new TreeBuilder('nelmio_api_doc');
  18.         if (method_exists($treeBuilder'getRootNode')) {
  19.             $rootNode $treeBuilder->getRootNode();
  20.         } else {
  21.             // symfony < 4.2 support
  22.             $rootNode $treeBuilder->root('nelmio_api_doc');
  23.         }
  24.         $rootNode
  25.             ->beforeNormalization()
  26.                 ->ifTrue(function ($v) {
  27.                     return !isset($v['areas']) && isset($v['routes']);
  28.                 })
  29.                 ->then(function ($v) {
  30.                     $v['areas'] = $v['routes'];
  31.                     unset($v['routes']);
  32.                     @trigger_error('The `nelmio_api_doc.routes` config option is deprecated. Please use `nelmio_api_doc.areas` instead (just replace `routes` by `areas` in your config).'E_USER_DEPRECATED);
  33.                     return $v;
  34.                 })
  35.             ->end()
  36.             ->beforeNormalization()
  37.                 ->ifTrue(function ($v) {
  38.                     return isset($v['routes']);
  39.                 })
  40.                 ->thenInvalid('You must not use both `nelmio_api_doc.areas` and `nelmio_api_doc.routes` config options. Please update your config to only use `nelmio_api_doc.areas`.')
  41.             ->end()
  42.             ->children()
  43.                 ->arrayNode('documentation')
  44.                     ->useAttributeAsKey('key')
  45.                     ->info('The documentation used as base')
  46.                     ->example(['info' => ['title' => 'My App']])
  47.                     ->prototype('variable')->end()
  48.                 ->end()
  49.                 ->arrayNode('areas')
  50.                     ->info('Filter the routes that are documented')
  51.                     ->defaultValue(
  52.                         [
  53.                             'default' => [
  54.                                 'path_patterns' => [],
  55.                                 'host_patterns' => [],
  56.                                 'with_annotation' => false,
  57.                                 'documentation' => [],
  58.                             ],
  59.                         ]
  60.                     )
  61.                     ->beforeNormalization()
  62.                         ->ifTrue(function ($v) {
  63.                             return === count($v) || isset($v['path_patterns']) || isset($v['host_patterns']) || isset($v['documentation']);
  64.                         })
  65.                         ->then(function ($v) {
  66.                             return ['default' => $v];
  67.                         })
  68.                     ->end()
  69.                     ->validate()
  70.                         ->ifTrue(function ($v) {
  71.                             return !isset($v['default']);
  72.                         })
  73.                         ->thenInvalid('You must specify a `default` area under `nelmio_api_doc.areas`.')
  74.                     ->end()
  75.                     ->useAttributeAsKey('name')
  76.                     ->prototype('array')
  77.                         ->addDefaultsIfNotSet()
  78.                         ->children()
  79.                             ->arrayNode('path_patterns')
  80.                                 ->defaultValue([])
  81.                                 ->example(['^/api''^/api(?!/admin)'])
  82.                                 ->prototype('scalar')->end()
  83.                             ->end()
  84.                             ->arrayNode('host_patterns')
  85.                                 ->defaultValue([])
  86.                                 ->example(['^api\.'])
  87.                                 ->prototype('scalar')->end()
  88.                             ->end()
  89.                             ->booleanNode('with_annotation')
  90.                                 ->defaultFalse()
  91.                                 ->info('whether to filter by annotation')
  92.                             ->end()
  93.                             ->arrayNode('documentation')
  94.                                 ->useAttributeAsKey('key')
  95.                                 ->defaultValue([])
  96.                                 ->info('The documentation used for area')
  97.                                 ->example(['info' => ['title' => 'My App']])
  98.                                 ->prototype('variable')->end()
  99.                             ->end()
  100.                         ->end()
  101.                     ->end()
  102.                 ->end()
  103.                 ->arrayNode('models')
  104.                     ->addDefaultsIfNotSet()
  105.                     ->children()
  106.                         ->booleanNode('use_jms')->defaultFalse()->end()
  107.                     ->end()
  108.                     ->children()
  109.                         ->arrayNode('names')
  110.                             ->prototype('array')
  111.                                 ->children()
  112.                                     ->scalarNode('alias')->isRequired()->end()
  113.                                     ->scalarNode('type')->isRequired()->end()
  114.                                     ->variableNode('groups')
  115.                                         ->defaultValue(null)
  116.                                         ->validate()
  117.                                             ->ifTrue(function ($v) { return null !== $v && !is_array($v); })
  118.                                             ->thenInvalid('Model groups must be either `null` or an array.')
  119.                                         ->end()
  120.                                     ->end()
  121.                                     ->arrayNode('areas')
  122.                                         ->defaultValue([])
  123.                                         ->prototype('scalar')->end()
  124.                                     ->end()
  125.                                 ->end()
  126.                         ->end()
  127.                     ->end()
  128.                 ->end()
  129.             ->end();
  130.         return $treeBuilder;
  131.     }
  132. }