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