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
|
|
|
public function getAlias() |
22
|
|
|
{ |
23
|
|
|
return 'core23_antispam'; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
27
|
|
|
{ |
28
|
|
|
$configuration = new Configuration(); |
29
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
30
|
|
|
|
31
|
|
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
32
|
|
|
$loader->load('services.xml'); |
33
|
|
|
|
34
|
|
|
$this->configureTwig($config, $container); |
35
|
|
|
$this->configureTime($container, $config); |
36
|
|
|
$this->configureHoneypot($container, $config); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param array $config |
41
|
|
|
*/ |
42
|
|
|
private function configureTwig($config, ContainerBuilder $container): void |
43
|
|
|
{ |
44
|
|
|
$container->setParameter('core23_antispam.twig.mail_css_class', $config['twig']['mail']['css_class']); |
45
|
|
|
$container->setParameter('core23_antispam.twig.mail_at_text', $config['twig']['mail']['at_text']); |
46
|
|
|
$container->setParameter('core23_antispam.twig.mail_dot_text', $config['twig']['mail']['dot_text']); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
private function configureTime(ContainerBuilder $container, array $config): void |
50
|
|
|
{ |
51
|
|
|
$container |
52
|
|
|
->getDefinition('core23_antispam.form.extension.type.time') |
53
|
|
|
->replaceArgument(2, $config['time']) |
54
|
|
|
; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
private function configureHoneypot(ContainerBuilder $container, array $config): void |
58
|
|
|
{ |
59
|
|
|
$container |
60
|
|
|
->getDefinition('core23_antispam.form.extension.type.honeypot') |
61
|
|
|
->replaceArgument(1, $config['honeypot']) |
62
|
|
|
; |
63
|
|
|
|
64
|
|
|
$container->setAlias('core23_antispam.provider', $config['honeypot']['provider']); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|