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

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();
  18.         $treeBuilder
  19.             ->root('nelmio_api_doc')
  20.             ->beforeNormalization()
  21.                 ->ifTrue(function ($v) {
  22.                     return !isset($v['areas']) && isset($v['routes']);
  23.                 })
  24.                 ->then(function ($v) {
  25.                     $v['areas'] = $v['routes'];
  26.                     unset($v['routes']);
  27.                     @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);
  28.                     return $v;
  29.                 })
  30.             ->end()
  31.             ->beforeNormalization()
  32.                 ->ifTrue(function ($v) {
  33.                     return isset($v['routes']);
  34.                 })
  35.                 ->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`.')
  36.             ->end()
  37.             ->children()
  38.                 ->arrayNode('documentation')
  39.                     ->useAttributeAsKey('key')
  40.                     ->info('The documentation used as base')
  41.                     ->example(['info' => ['title' => 'My App']])
  42.                     ->prototype('variable')->end()
  43.                 ->end()
  44.                 ->arrayNode('areas')
  45.                     ->info('Filter the routes that are documented')
  46.                     ->defaultValue(['default' => ['path_patterns' => []]])
  47.                     ->beforeNormalization()
  48.                         ->ifTrue(function ($v) {
  49.                             return empty($v) or isset($v['path_patterns']);
  50.                         })
  51.                         ->then(function ($v) {
  52.                             return ['default' => $v];
  53.                         })
  54.                     ->end()
  55.                     ->validate()
  56.                         ->ifTrue(function ($v) {
  57.                             return !isset($v['default']);
  58.                         })
  59.                         ->thenInvalid('You must specify a `default` area under `nelmio_api_doc.areas`.')
  60.                     ->end()
  61.                     ->useAttributeAsKey('name')
  62.                     ->prototype('array')
  63.                         ->addDefaultsIfNotSet()
  64.                         ->children()
  65.                             ->arrayNode('path_patterns')
  66.                                 ->example(['^/api''^/api(?!/admin)'])
  67.                                 ->prototype('scalar')->end()
  68.                             ->end()
  69.                         ->end()
  70.                     ->end()
  71.                 ->end()
  72.                 ->arrayNode('models')
  73.                     ->addDefaultsIfNotSet()
  74.                     ->children()
  75.                         ->booleanNode('use_jms')->defaultFalse()->end()
  76.                     ->end()
  77.                 ->end()
  78.             ->end();
  79.         return $treeBuilder;
  80.     }
  81. }