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
|
|
|
namespace FSi\Bundle\AdminSecurityBundle\DependencyInjection; |
11
|
|
|
|
12
|
|
|
use FSi\Bundle\AdminSecurityBundle\Form\TypeSolver; |
13
|
|
|
use Symfony\Component\Config\FileLocator; |
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
15
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
16
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
17
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Norbert Orzechowicz <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class FSIAdminSecurityExtension extends Extension implements PrependExtensionInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
public function load(array $configs, ContainerBuilder $container) |
28
|
|
|
{ |
29
|
|
|
$configuration = new Configuration(); |
30
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
31
|
|
|
|
32
|
|
|
$container->setParameter('admin_security.storage', $config['storage']); |
33
|
|
|
$container->setParameter('admin_security.firewall_name', $config['firewall_name']); |
34
|
|
|
$this->setTemplateParameters($container, 'admin_security.templates', $config['templates']); |
35
|
|
|
$this->setModelParameters($container, $config['model']); |
36
|
|
|
$this->setActivationParameters($container, $config['activation']); |
37
|
|
|
$this->setPasswordResetParameters($container, $config['password_reset']); |
38
|
|
|
$this->setChangePasswordParameters($container, $config['change_password']); |
39
|
|
|
|
40
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
41
|
|
|
$loader->load('services.xml'); |
42
|
|
|
$loader->load(sprintf('%s.xml', $config['storage'])); |
43
|
|
|
$loader->load( |
44
|
|
|
TypeSolver::isSymfony3FormNamingConvention() ? 'forms-symfony-3.xml' : 'forms-symfony-2.xml' |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function prepend(ContainerBuilder $container) |
49
|
|
|
{ |
50
|
|
|
$container->prependExtensionConfig('fsi_admin', [ |
51
|
|
|
'templates' => [ |
52
|
|
|
'datagrid_theme' => '@FSiAdminSecurity/Admin/datagrid.html.twig' |
53
|
|
|
] |
54
|
|
|
]); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
59
|
|
|
* @param array $config |
60
|
|
|
*/ |
61
|
|
|
protected function setTemplateParameters(ContainerBuilder $container, $prefix, $config = []) |
62
|
|
|
{ |
63
|
|
|
foreach ($config as $key => $value) { |
64
|
|
|
$parameterName = join('.', [$prefix, $key]); |
65
|
|
|
if (is_array($value)) { |
66
|
|
|
$this->setTemplateParameters($container, $parameterName, $value); |
67
|
|
|
continue; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$container->setParameter($parameterName, $value); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
protected function setModelParameters(ContainerBuilder $container, $model) |
75
|
|
|
{ |
76
|
|
|
$container->setParameter('admin_security.model.user', $model['user']); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
private function setActivationParameters(ContainerBuilder $container, $model) |
80
|
|
|
{ |
81
|
|
|
$container->setParameter('admin_security.activation.token_ttl', $model['token_ttl']); |
82
|
|
|
$container->setParameter('admin_security.activation.token_length', $model['token_length']); |
83
|
|
|
$container->setParameter('admin_security.activation.mailer.template', $model['mailer']['template']); |
84
|
|
|
$container->setParameter('admin_security.activation.mailer.from', $model['mailer']['from']); |
85
|
|
|
$container->setParameter('admin_security.activation.mailer.reply_to', $model['mailer']['reply_to']); |
86
|
|
|
$container->setParameter( |
87
|
|
|
'admin_security.activation.change_password_form.type', |
88
|
|
|
$model['change_password_form']['type'] |
89
|
|
|
); |
90
|
|
|
$container->setParameter( |
91
|
|
|
'admin_security.activation.change_password_form.validation_groups', |
92
|
|
|
$model['change_password_form']['validation_groups'] |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
private function setPasswordResetParameters(ContainerBuilder $container, $model) |
97
|
|
|
{ |
98
|
|
|
$container->setParameter('admin_security.password_reset.token_ttl', $model['token_ttl']); |
99
|
|
|
$container->setParameter('admin_security.password_reset.token_length', $model['token_length']); |
100
|
|
|
$container->setParameter('admin_security.password_reset.mailer.template', $model['mailer']['template']); |
101
|
|
|
$container->setParameter('admin_security.password_reset.mailer.from', $model['mailer']['from']); |
102
|
|
|
$container->setParameter('admin_security.password_reset.mailer.reply_to', $model['mailer']['reply_to']); |
103
|
|
|
$container->setParameter( |
104
|
|
|
'admin_security.password_reset.request_form.type', |
105
|
|
|
$model['request_form']['type'] |
106
|
|
|
); |
107
|
|
|
$container->setParameter( |
108
|
|
|
'admin_security.password_reset.change_password_form.type', |
109
|
|
|
$model['change_password_form']['type'] |
110
|
|
|
); |
111
|
|
|
$container->setParameter( |
112
|
|
|
'admin_security.password_reset.change_password_form.validation_groups', |
113
|
|
|
$model['change_password_form']['validation_groups'] |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
private function setChangePasswordParameters(ContainerBuilder $container, $model) |
118
|
|
|
{ |
119
|
|
|
$container->setParameter( |
120
|
|
|
'admin_security.change_password.form.type', |
121
|
|
|
$model['form']['type'] |
122
|
|
|
); |
123
|
|
|
$container->setParameter( |
124
|
|
|
'admin_security.change_password.form.validation_groups', |
125
|
|
|
$model['form']['validation_groups'] |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|