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

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