1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* (c) Christian Gripp <[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 Core23\AntiSpamBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
15
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
16
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
17
|
|
|
|
18
|
|
|
final class Configuration implements ConfigurationInterface |
19
|
|
|
{ |
20
|
|
|
public function getConfigTreeBuilder() |
21
|
|
|
{ |
22
|
|
|
$treeBuilder = new TreeBuilder('core23_antispam'); |
23
|
|
|
|
24
|
|
|
$rootNode = $treeBuilder->getRootNode(); |
25
|
|
|
|
26
|
|
|
\assert($rootNode instanceof ArrayNodeDefinition); |
27
|
|
|
|
28
|
|
|
$this->addTwigSection($rootNode); |
29
|
|
|
$this->addTimeSection($rootNode); |
30
|
|
|
$this->addHoneypotSection($rootNode); |
31
|
|
|
|
32
|
|
|
return $treeBuilder; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
private function addTwigSection(ArrayNodeDefinition $node): void |
36
|
|
|
{ |
37
|
|
|
$node |
38
|
|
|
->children() |
39
|
|
|
->arrayNode('twig') |
40
|
|
|
->addDefaultsIfNotSet() |
41
|
|
|
->children() |
42
|
|
|
->arrayNode('mail') |
43
|
|
|
->addDefaultsIfNotSet() |
44
|
|
|
->children() |
45
|
|
|
->scalarNode('css_class')->defaultNull()->end() |
46
|
|
|
->arrayNode('dot_text') |
47
|
|
|
->useAttributeAsKey('id') |
48
|
|
|
->requiresAtLeastOneElement() |
49
|
|
|
->defaultValue(['[DOT]', '(DOT)', '[.]']) |
50
|
|
|
->prototype('scalar')->end() |
51
|
|
|
->end() |
52
|
|
|
->arrayNode('at_text') |
53
|
|
|
->useAttributeAsKey('id') |
54
|
|
|
->requiresAtLeastOneElement() |
55
|
|
|
->defaultValue(['[AT]', '(AT)', '[ÄT]']) |
56
|
|
|
->prototype('scalar')->end() |
57
|
|
|
->end() |
58
|
|
|
->end() |
59
|
|
|
->end() |
60
|
|
|
->end() |
61
|
|
|
->end() |
62
|
|
|
->end() |
63
|
|
|
; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
private function addTimeSection(ArrayNodeDefinition $node): void |
67
|
|
|
{ |
68
|
|
|
$node |
69
|
|
|
->children() |
70
|
|
|
->arrayNode('time') |
71
|
|
|
->addDefaultsIfNotSet() |
72
|
|
|
->children() |
73
|
|
|
->integerNode('min')->defaultValue(5)->end() |
74
|
|
|
->integerNode('max')->defaultValue(3600)->end() |
75
|
|
|
->booleanNode('global')->defaultFalse()->end() |
76
|
|
|
->end() |
77
|
|
|
->end() |
78
|
|
|
->end() |
79
|
|
|
; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
private function addHoneypotSection(ArrayNodeDefinition $node): void |
83
|
|
|
{ |
84
|
|
|
$node |
85
|
|
|
->children() |
86
|
|
|
->arrayNode('honeypot') |
87
|
|
|
->addDefaultsIfNotSet() |
88
|
|
|
->children() |
89
|
|
|
->scalarNode('field')->defaultValue('email_address')->end() |
90
|
|
|
->scalarNode('class') |
91
|
|
|
->defaultValue('hidden') |
92
|
|
|
->info('CSS class to hide the honeypot. If not set a "style:hidden" attribute ist set.') |
93
|
|
|
->end() |
94
|
|
|
->booleanNode('global')->defaultFalse()->end() |
95
|
|
|
->scalarNode('provider')->defaultValue('core23_antispam.provider.session')->end() |
96
|
|
|
->end() |
97
|
|
|
->end() |
98
|
|
|
->end() |
99
|
|
|
; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|