vendor/friendsofsymfony/oauth-server-bundle/DependencyInjection/Configuration.php line 35

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the FOSOAuthServerBundle package.
  5.  *
  6.  * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace FOS\OAuthServerBundle\DependencyInjection;
  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 is the class that validates and merges configuration from your app/config files.
  17.  *
  18.  * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
  19.  */
  20. class Configuration implements ConfigurationInterface
  21. {
  22.     /**
  23.      * {@inheritdoc}
  24.      */
  25.     public function getConfigTreeBuilder()
  26.     {
  27.         $treeBuilder = new TreeBuilder();
  28.         /** @var ArrayNodeDefinition $rootNode */
  29.         $rootNode $treeBuilder->root('fos_oauth_server');
  30.         $supportedDrivers = ['orm''mongodb''propel''custom'];
  31.         $rootNode
  32.             ->validate()
  33.                 ->always(function ($v) {
  34.                     if ('custom' !== $v['db_driver']) {
  35.                         return $v;
  36.                     }
  37.                     if (empty($v['service']['client_manager']) || $v['service']['client_manager'] === 'fos_oauth_server.client_manager.default') {
  38.                         throw new \InvalidArgumentException('The service client_manager must be set explicitly for custom db_driver.');
  39.                     }
  40.                     if (empty($v['service']['access_token_manager']) || $v['service']['access_token_manager'] === 'fos_oauth_server.access_token_manager.default') {
  41.                         throw new \InvalidArgumentException('The service access_token_manager must be set explicitly for custom db_driver.');
  42.                     }
  43.                     if (empty($v['service']['refresh_token_manager']) || $v['service']['refresh_token_manager'] === 'fos_oauth_server.refresh_token_manager.default') {
  44.                         throw new \InvalidArgumentException('The service refresh_token_manager must be set explicitly for custom db_driver.');
  45.                     }
  46.                     if (empty($v['service']['auth_code_manager']) || $v['service']['auth_code_manager'] === 'fos_oauth_server.auth_code_manager.default') {
  47.                         throw new \InvalidArgumentException('The service auth_code_manager must be set explicitly for custom db_driver.');
  48.                     }
  49.                     return $v;
  50.                 })
  51.             ->end()
  52.             ->children()
  53.                 ->scalarNode('db_driver')
  54.                     ->validate()
  55.                         ->ifNotInArray($supportedDrivers)
  56.                         ->thenInvalid('The driver %s is not supported. Please choose one of '.json_encode($supportedDrivers))
  57.                     ->end()
  58.                     ->isRequired()
  59.                     ->cannotBeEmpty()
  60.                 ->end()
  61.                 ->scalarNode('client_class')->isRequired()->cannotBeEmpty()->end()
  62.                 ->scalarNode('access_token_class')->isRequired()->cannotBeEmpty()->end()
  63.                 ->scalarNode('refresh_token_class')->isRequired()->cannotBeEmpty()->end()
  64.                 ->scalarNode('auth_code_class')->isRequired()->cannotBeEmpty()->end()
  65.                 ->scalarNode('model_manager_name')->defaultNull()->end()
  66.             ->end()
  67.         ;
  68.         $this->addAuthorizeSection($rootNode);
  69.         $this->addServiceSection($rootNode);
  70.         $this->addTemplateSection($rootNode);
  71.         return $treeBuilder;
  72.     }
  73.     private function addAuthorizeSection(ArrayNodeDefinition $node)
  74.     {
  75.         $node
  76.             ->children()
  77.                 ->arrayNode('authorize')
  78.                     ->addDefaultsIfNotSet()
  79.                     ->canBeUnset()
  80.                     ->children()
  81.                         ->arrayNode('form')
  82.                             ->addDefaultsIfNotSet()
  83.                             ->children()
  84.                                 ->scalarNode('type')->defaultValue('fos_oauth_server_authorize')->end()
  85.                                 ->scalarNode('handler')->defaultValue('fos_oauth_server.authorize.form.handler.default')->end()
  86.                                 ->scalarNode('name')->defaultValue('fos_oauth_server_authorize_form')->cannotBeEmpty()->end()
  87.                                 ->arrayNode('validation_groups')
  88.                                     ->prototype('scalar')->end()
  89.                                     ->defaultValue(['Authorize''Default'])
  90.                                 ->end()
  91.                             ->end()
  92.                         ->end()
  93.                     ->end()
  94.                 ->end()
  95.             ->end()
  96.         ;
  97.     }
  98.     private function addServiceSection(ArrayNodeDefinition $node)
  99.     {
  100.         $node
  101.             ->addDefaultsIfNotSet()
  102.             ->children()
  103.                 ->arrayNode('service')
  104.                     ->addDefaultsIfNotSet()
  105.                         ->children()
  106.                             ->scalarNode('storage')->defaultValue('fos_oauth_server.storage.default')->cannotBeEmpty()->end()
  107.                             ->scalarNode('user_provider')->defaultNull()->end()
  108.                             ->scalarNode('client_manager')->defaultValue('fos_oauth_server.client_manager.default')->end()
  109.                             ->scalarNode('access_token_manager')->defaultValue('fos_oauth_server.access_token_manager.default')->end()
  110.                             ->scalarNode('refresh_token_manager')->defaultValue('fos_oauth_server.refresh_token_manager.default')->end()
  111.                             ->scalarNode('auth_code_manager')->defaultValue('fos_oauth_server.auth_code_manager.default')->end()
  112.                             ->arrayNode('options')
  113.                                 ->useAttributeAsKey('key')
  114.                                 ->treatNullLike([])
  115.                                 ->prototype('variable')->end()
  116.                             ->end()
  117.                         ->end()
  118.                     ->end()
  119.                 ->end()
  120.             ->end()
  121.         ;
  122.     }
  123.     private function addTemplateSection(ArrayNodeDefinition $node)
  124.     {
  125.         $node
  126.             ->children()
  127.                 ->arrayNode('template')
  128.                     ->addDefaultsIfNotSet()
  129.                     ->children()
  130.                         ->scalarNode('engine')->defaultValue('twig')->end()
  131.                     ->end()
  132.                 ->end()
  133.             ->end()
  134.         ;
  135.     }
  136. }