|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Zenstruck\Foundry\Bundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
6
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @author Kevin Bond <[email protected]> |
|
10
|
|
|
*/ |
|
11
|
|
|
final class Configuration implements ConfigurationInterface |
|
12
|
|
|
{ |
|
13
|
104 |
|
public function getConfigTreeBuilder(): TreeBuilder |
|
14
|
|
|
{ |
|
15
|
104 |
|
$treeBuilder = new TreeBuilder('zenstruck_foundry'); |
|
16
|
|
|
|
|
17
|
104 |
|
$treeBuilder->getRootNode() |
|
18
|
104 |
|
->children() |
|
19
|
104 |
|
->booleanNode('auto_refresh_proxies') |
|
20
|
104 |
|
->info('Whether to auto-refresh proxies by default (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#auto-refresh)') |
|
21
|
104 |
|
->defaultNull() |
|
22
|
104 |
|
->end() |
|
23
|
104 |
|
->arrayNode('faker') |
|
24
|
104 |
|
->addDefaultsIfNotSet() |
|
25
|
104 |
|
->info('Configure faker to be used by your factories.') |
|
26
|
104 |
|
->validate() |
|
27
|
|
|
->ifTrue(static function(array $v) { |
|
28
|
30 |
|
return $v['locale'] && $v['service']; |
|
29
|
104 |
|
}) |
|
30
|
104 |
|
->thenInvalid('Cannot set faker locale when using custom service.') |
|
31
|
104 |
|
->end() |
|
32
|
104 |
|
->children() |
|
33
|
104 |
|
->scalarNode('locale') |
|
34
|
104 |
|
->defaultNull() |
|
35
|
104 |
|
->info('Change the default faker locale.') |
|
36
|
104 |
|
->example('fr_FR') |
|
37
|
104 |
|
->end() |
|
38
|
104 |
|
->scalarNode('service') |
|
39
|
104 |
|
->defaultNull() |
|
40
|
104 |
|
->info('Customize the faker service.') |
|
41
|
104 |
|
->example('my_faker') |
|
42
|
104 |
|
->end() |
|
43
|
104 |
|
->end() |
|
44
|
104 |
|
->end() |
|
45
|
104 |
|
->arrayNode('instantiator') |
|
46
|
104 |
|
->addDefaultsIfNotSet() |
|
47
|
104 |
|
->info('Configure the default instantiator used by your factories.') |
|
48
|
104 |
|
->validate() |
|
49
|
|
|
->ifTrue(static function(array $v) { |
|
50
|
50 |
|
return $v['service'] && $v['without_constructor']; |
|
51
|
104 |
|
}) |
|
52
|
104 |
|
->thenInvalid('Cannot set "without_constructor" when using custom service.') |
|
53
|
104 |
|
->end() |
|
54
|
104 |
|
->validate() |
|
55
|
|
|
->ifTrue(static function(array $v) { |
|
56
|
40 |
|
return $v['service'] && $v['allow_extra_attributes']; |
|
57
|
104 |
|
}) |
|
58
|
104 |
|
->thenInvalid('Cannot set "allow_extra_attributes" when using custom service.') |
|
59
|
104 |
|
->end() |
|
60
|
104 |
|
->validate() |
|
61
|
|
|
->ifTrue(static function(array $v) { |
|
62
|
30 |
|
return $v['service'] && $v['always_force_properties']; |
|
63
|
104 |
|
}) |
|
64
|
104 |
|
->thenInvalid('Cannot set "always_force_properties" when using custom service.') |
|
65
|
104 |
|
->end() |
|
66
|
104 |
|
->children() |
|
67
|
104 |
|
->booleanNode('without_constructor') |
|
68
|
104 |
|
->defaultFalse() |
|
69
|
104 |
|
->info('Whether or not to call an object\'s constructor during instantiation.') |
|
70
|
104 |
|
->end() |
|
71
|
104 |
|
->booleanNode('allow_extra_attributes') |
|
72
|
104 |
|
->defaultFalse() |
|
73
|
104 |
|
->info('Whether or not to allow extra attributes.') |
|
74
|
104 |
|
->end() |
|
75
|
104 |
|
->booleanNode('always_force_properties') |
|
76
|
104 |
|
->defaultFalse() |
|
77
|
104 |
|
->info('Whether or not to skip setters and force set object properties (public/private/protected) directly.') |
|
78
|
104 |
|
->end() |
|
79
|
104 |
|
->scalarNode('service') |
|
80
|
104 |
|
->defaultNull() |
|
81
|
104 |
|
->info('Customize the instantiator service.') |
|
82
|
104 |
|
->example('my_instantiator') |
|
83
|
104 |
|
->end() |
|
84
|
104 |
|
->end() |
|
85
|
104 |
|
->end() |
|
86
|
104 |
|
->end() |
|
87
|
|
|
; |
|
88
|
|
|
|
|
89
|
104 |
|
return $treeBuilder; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|