Configuration   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 37
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 50 1
1
<?php
2
3
/*
4
 * This file is part of the OneGuard DynamicConfigurationBundle.
5
 *
6
 * (c) OneGuard <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace OneGuard\Bundle\DynamicConfigurationBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
17
class Configuration implements ConfigurationInterface {
18
	public function getConfigTreeBuilder() {
19
		$treeBuilder = new TreeBuilder();
20
		$rootNode = $treeBuilder->root('one_guard_dynamic_configuration');
21
22
		$rootNode
23
			->addDefaultsIfNotSet()
24
			->children()
25
				->arrayNode('definitions')
26
					->prototype('array')
27
						->children()
28
							->enumNode('type')
29
								->values(['entity', 'string'])
30
								->isRequired()
31
							->end()
32
							->arrayNode('options')
33
								->children()
34
									->scalarNode('class')
35
										->validate()
36
											->ifTrue(function ($class) {
37
												return !class_exists($class);
38
											})
39
											->thenInvalid("Class doesn't exist.")
40
										->end()
41
									->end()
42
									->scalarNode('choice_label')->end()
43
								->end()
44
//								->validate()
45
//									->ifTrue(function ($options) {
46
//										if (!empty($options['class'])) {
47
//											$propertyAccessor = new PropertyAccessor();
48
//											return !$propertyAccessor->isReadable($options['class'], $options['choice_label']);
49
//										}
50
//										return true;
51
//									})
52
//									->thenInvalid("Property not accessible.")
53
//								->end()
54
							->end()
55
						->end()
56
					->end()
57
				->end()
58
				->scalarNode('translation_domain')
59
					->defaultValue('messages')
60
					->cannotBeEmpty()
61
				->end()
62
				->scalarNode('translation_prefix')
63
					->defaultValue('')
64
				->end()
65
			->end();
66
67
		return $treeBuilder;
68
	}
69
}
70