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\FileLocator; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
17
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
18
|
|
|
|
19
|
|
|
final class Core23AntiSpamExtension extends Extension |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function getAlias() |
25
|
|
|
{ |
26
|
|
|
return 'core23_antispam'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
33
|
|
|
{ |
34
|
|
|
$configuration = new Configuration(); |
35
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
36
|
|
|
|
37
|
|
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
38
|
|
|
$loader->load('services.xml'); |
39
|
|
|
|
40
|
|
|
$this->configureTwig($config, $container); |
41
|
|
|
$this->configureTime($container, $config); |
42
|
|
|
$this->configureHoneypot($container, $config); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param array $config |
47
|
|
|
* @param ContainerBuilder $container |
48
|
|
|
*/ |
49
|
|
|
private function configureTwig($config, ContainerBuilder $container): void |
50
|
|
|
{ |
51
|
|
|
$container->setParameter('core23_antispam.twig.mail_css_class', $config['twig']['mail']['css_class']); |
52
|
|
|
$container->setParameter('core23_antispam.twig.mail_at_text', $config['twig']['mail']['at_text']); |
53
|
|
|
$container->setParameter('core23_antispam.twig.mail_dot_text', $config['twig']['mail']['dot_text']); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param ContainerBuilder $container |
58
|
|
|
* @param array $config |
59
|
|
|
*/ |
60
|
|
|
private function configureTime(ContainerBuilder $container, array $config): void |
61
|
|
|
{ |
62
|
|
|
$container |
63
|
|
|
->getDefinition('core23_antispam.form.extension.type.time') |
64
|
|
|
->replaceArgument(2, $config['time']); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param ContainerBuilder $container |
69
|
|
|
* @param array $config |
70
|
|
|
*/ |
71
|
|
|
private function configureHoneypot(ContainerBuilder $container, array $config): void |
72
|
|
|
{ |
73
|
|
|
$container |
74
|
|
|
->getDefinition('core23_antispam.form.extension.type.honeypot') |
75
|
|
|
->replaceArgument(1, $config['honeypot']); |
76
|
|
|
|
77
|
|
|
$container->setAlias('core23_antispam.provider', $config['honeypot']['provider']); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|