1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) FSi sp. z o.o. <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace FSi\Bundle\AdminSecurityBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\FileLocator; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
17
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
18
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
19
|
|
|
|
20
|
|
|
class FSIAdminSecurityExtension extends Extension implements PrependExtensionInterface |
21
|
|
|
{ |
22
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
23
|
|
|
{ |
24
|
|
|
$configuration = new Configuration(); |
25
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
26
|
|
|
|
27
|
|
|
$container->setParameter('admin_security.storage', $config['storage']); |
28
|
|
|
$container->setParameter('admin_security.firewall_name', $config['firewall_name']); |
29
|
|
|
$this->setTemplateParameters($container, 'admin_security.templates', $config['templates']); |
30
|
|
|
$this->setModelParameters($container, $config['model']); |
31
|
|
|
$this->setActivationParameters($container, $config['activation']); |
32
|
|
|
$this->setPasswordResetParameters($container, $config['password_reset']); |
33
|
|
|
$this->setChangePasswordParameters($container, $config['change_password']); |
34
|
|
|
|
35
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
36
|
|
|
$loader->load('services.xml'); |
37
|
|
|
$loader->load(sprintf('%s.xml', $config['storage'])); |
38
|
|
|
$loader->load('forms.xml'); |
39
|
|
|
$loader->load('commands.xml'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function prepend(ContainerBuilder $container): void |
43
|
|
|
{ |
44
|
|
|
$container->prependExtensionConfig('fsi_admin', [ |
45
|
|
|
'templates' => [ |
46
|
|
|
'datagrid_theme' => '@FSiAdminSecurity/Admin/datagrid.html.twig' |
47
|
|
|
] |
48
|
|
|
]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function setTemplateParameters(ContainerBuilder $container, string $prefix, array $config = []): void |
52
|
|
|
{ |
53
|
|
|
foreach ($config as $key => $value) { |
54
|
|
|
$parameterName = implode('.', [$prefix, $key]); |
55
|
|
|
if (is_array($value)) { |
56
|
|
|
$this->setTemplateParameters($container, $parameterName, $value); |
57
|
|
|
continue; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$container->setParameter($parameterName, $value); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
protected function setModelParameters(ContainerBuilder $container, array $model): void |
65
|
|
|
{ |
66
|
|
|
$container->setParameter('admin_security.model.user', $model['user']); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
private function setActivationParameters(ContainerBuilder $container, array $model): void |
70
|
|
|
{ |
71
|
|
|
$container->setParameter('admin_security.activation.token_ttl', $model['token_ttl']); |
72
|
|
|
$container->setParameter('admin_security.activation.token_length', $model['token_length']); |
73
|
|
|
$container->setParameter('admin_security.activation.mailer.template', $model['mailer']['template']); |
74
|
|
|
$container->setParameter('admin_security.activation.mailer.template_new_token', $model['mailer']['template_new_token']); |
75
|
|
|
$container->setParameter('admin_security.activation.mailer.from', $model['mailer']['from']); |
76
|
|
|
$container->setParameter('admin_security.activation.mailer.reply_to', $model['mailer']['reply_to']); |
77
|
|
|
$container->setParameter( |
78
|
|
|
'admin_security.activation.change_password_form.type', |
79
|
|
|
$model['change_password_form']['type'] |
80
|
|
|
); |
81
|
|
|
$container->setParameter( |
82
|
|
|
'admin_security.activation.change_password_form.validation_groups', |
83
|
|
|
$model['change_password_form']['validation_groups'] |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
private function setPasswordResetParameters(ContainerBuilder $container, array $model): void |
88
|
|
|
{ |
89
|
|
|
$container->setParameter('admin_security.password_reset.token_ttl', $model['token_ttl']); |
90
|
|
|
$container->setParameter('admin_security.password_reset.token_length', $model['token_length']); |
91
|
|
|
$container->setParameter('admin_security.password_reset.mailer.template', $model['mailer']['template']); |
92
|
|
|
$container->setParameter('admin_security.password_reset.mailer.from', $model['mailer']['from']); |
93
|
|
|
$container->setParameter('admin_security.password_reset.mailer.reply_to', $model['mailer']['reply_to']); |
94
|
|
|
$container->setParameter( |
95
|
|
|
'admin_security.password_reset.request_form.type', |
96
|
|
|
$model['request_form']['type'] |
97
|
|
|
); |
98
|
|
|
$container->setParameter( |
99
|
|
|
'admin_security.password_reset.change_password_form.type', |
100
|
|
|
$model['change_password_form']['type'] |
101
|
|
|
); |
102
|
|
|
$container->setParameter( |
103
|
|
|
'admin_security.password_reset.change_password_form.validation_groups', |
104
|
|
|
$model['change_password_form']['validation_groups'] |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
private function setChangePasswordParameters(ContainerBuilder $container, array $model): void |
109
|
|
|
{ |
110
|
|
|
$container->setParameter( |
111
|
|
|
'admin_security.change_password.form.type', |
112
|
|
|
$model['form']['type'] |
113
|
|
|
); |
114
|
|
|
$container->setParameter( |
115
|
|
|
'admin_security.change_password.form.validation_groups', |
116
|
|
|
$model['form']['validation_groups'] |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|