1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2014 SURFnet bv |
7
|
|
|
* |
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
9
|
|
|
* you may not use this file except in compliance with the License. |
10
|
|
|
* You may obtain a copy of the License at |
11
|
|
|
* |
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
* |
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17
|
|
|
* See the License for the specific language governing permissions and |
18
|
|
|
* limitations under the License. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace Surfnet\YubikeyApiClientBundle\DependencyInjection; |
22
|
|
|
|
23
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
24
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @codeCoverageIgnore |
28
|
|
|
*/ |
29
|
|
|
class Configuration implements ConfigurationInterface |
30
|
|
|
{ |
31
|
|
|
public function getConfigTreeBuilder(): TreeBuilder |
32
|
|
|
{ |
33
|
|
|
$treeBuilder = new TreeBuilder('surfnet_yubikey_api_client'); |
34
|
|
|
|
35
|
|
|
$rootNode = $treeBuilder->getRootNode(); |
36
|
|
|
$rootNode |
37
|
|
|
->children() |
38
|
|
|
->arrayNode('credentials') |
39
|
|
|
->info('YubiKey API Credentials') |
40
|
|
|
->children() |
41
|
|
|
->scalarNode('client_id') |
42
|
|
|
->info('Client ID for the YubiKey API') |
43
|
|
|
->isRequired() |
44
|
|
|
->validate() |
45
|
|
|
->ifTrue(function ($value) { |
46
|
|
|
return (!is_string($value) && !is_int($value)) || trim((string)$value) === ''; |
47
|
|
|
}) |
48
|
|
|
->thenInvalid('Invalid YubiKey API Client ID specified: "%s"') |
49
|
|
|
->end() |
50
|
|
|
->end() |
51
|
|
|
->scalarNode('client_secret') |
52
|
|
|
->info('Secret for the YubiKey API') |
53
|
|
|
->isRequired() |
54
|
|
|
->validate() |
55
|
|
|
->ifTrue(function ($value) { |
56
|
|
|
return (!is_string($value) || trim($value) === ''); |
57
|
|
|
}) |
58
|
|
|
->thenInvalid('Invalid YubiKey API secret specified: "%s"') |
59
|
|
|
->end() |
60
|
|
|
->end() |
61
|
|
|
->end() |
62
|
|
|
->end() |
63
|
|
|
->end(); |
64
|
|
|
|
65
|
|
|
return $treeBuilder; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|