Issues (57)

DependencyInjection/Configuration.php (1 issue)

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 FSi\Bundle\AdminSecurityBundle\Form\Type\Admin\ChangePasswordType;
15
use FSi\Bundle\AdminSecurityBundle\Form\Type\PasswordReset;
16
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
17
use Symfony\Component\Config\Definition\ConfigurationInterface;
18
19
class Configuration implements ConfigurationInterface
20
{
21
    public function getConfigTreeBuilder(): TreeBuilder
22
    {
23
        if (true === method_exists(TreeBuilder::class, 'getRootNode')) {
24
            $treeBuilder = new TreeBuilder('fsi_admin_security');
25
            $rootNode = $treeBuilder->getRootNode();
26
        } else {
27
            $treeBuilder = new TreeBuilder();
28
            $rootNode = $treeBuilder->root('fsi_admin_security');
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Config...der\TreeBuilder::root() has been deprecated: since Symfony 4.3, pass the root name to the constructor instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

28
            $rootNode = /** @scrutinizer ignore-deprecated */ $treeBuilder->root('fsi_admin_security');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
29
        }
30
31
        $supportedStorages = ['orm'];
32
33
        $rootNode
34
            ->beforeNormalization()
35
                ->always(function($v) {
36
                    if (isset($v['mailer']['from'])) {
37
                        if (!isset($v['activation']['mailer']['from'])) {
38
                            $v['activation']['mailer']['from'] = $v['mailer']['from'];
39
                        }
40
                        if (!isset($v['password_reset']['mailer']['from'])) {
41
                            $v['password_reset']['mailer']['from'] = $v['mailer']['from'];
42
                        }
43
                    }
44
45
                    if (isset($v['mailer']['reply_to'])) {
46
                        if (!isset($v['activation']['mailer']['reply_to'])) {
47
                            $v['activation']['mailer']['reply_to'] = $v['mailer']['reply_to'];
48
                        }
49
                        if (!isset($v['password_reset']['mailer']['reply_to'])) {
50
                            $v['password_reset']['mailer']['reply_to'] = $v['mailer']['reply_to'];
51
                        }
52
                    }
53
54
                    return $v;
55
                })
56
            ->end()
57
            ->children()
58
                ->scalarNode('storage')
59
                    ->validate()
60
                        ->ifNotInArray($supportedStorages)
61
                        ->thenInvalid('The driver %s is not supported. Please choose one of ' . json_encode($supportedStorages))
62
                    ->end()
63
                    ->cannotBeOverwritten()
64
                    ->isRequired()
65
                    ->cannotBeEmpty()
66
                ->end()
67
                ->scalarNode('firewall_name')->isRequired()->cannotBeEmpty()->end()
68
                ->arrayNode('model')
69
                    ->isRequired()
70
                    ->children()
71
                        ->scalarNode('user')->cannotBeEmpty()->isRequired()->end()
72
                    ->end()
73
                ->end()
74
                ->arrayNode('mailer')
75
                    ->children()
76
                        ->scalarNode('from')->defaultNull()->end()
77
                        ->scalarNode('reply_to')->defaultNull()->end()
78
                    ->end()
79
                ->end()
80
                ->arrayNode('activation')
81
                    ->isRequired()
82
                    ->addDefaultsIfNotSet()
83
                    ->children()
84
                        ->integerNode('token_ttl')
85
                            ->min(0)
86
                            ->defaultValue(43200) // 12h
87
                            ->max(172800) // 48h
88
                        ->end()
89
                        ->integerNode('token_length')
90
                            ->min(16)
91
                            ->defaultValue(32)
92
                            ->max(64)
93
                        ->end()
94
                        ->arrayNode('mailer')
95
                            ->isRequired()
96
                            ->addDefaultsIfNotSet()
97
                            ->children()
98
                                ->scalarNode('from')->cannotBeEmpty()->isRequired()->end()
99
                                ->scalarNode('template')->defaultValue('@FSiAdminSecurity/Activation/mail.html.twig')->end()
100
                                ->scalarNode('template_new_token')->defaultValue('@FSiAdminSecurity/Activation/mailNewToken.html.twig')->end()
101
                                ->scalarNode('reply_to')->defaultNull()->end()
102
                            ->end()
103
                        ->end()
104
                        ->arrayNode('change_password_form')
105
                            ->addDefaultsIfNotSet()
106
                            ->children()
107
                                ->scalarNode('type')->defaultValue(PasswordReset\ChangePasswordType::class)->end()
108
                                ->arrayNode('validation_groups')
109
                                    ->prototype('scalar')->end()
110
                                    ->defaultValue(['ResetPassword', 'Default'])
111
                                ->end()
112
                            ->end()
113
                        ->end()
114
                    ->end()
115
                ->end()
116
                ->arrayNode('password_reset')
117
                    ->isRequired()
118
                    ->addDefaultsIfNotSet()
119
                    ->children()
120
                        ->integerNode('token_ttl')
121
                            ->min(0)
122
                            ->defaultValue(43200) // 12h
123
                            ->max(172800) // 48h
124
                        ->end()
125
                        ->integerNode('token_length')
126
                            ->min(16)
127
                            ->defaultValue(32)
128
                            ->max(64)
129
                        ->end()
130
                        ->arrayNode('mailer')
131
                            ->isRequired()
132
                            ->addDefaultsIfNotSet()
133
                            ->children()
134
                                ->scalarNode('from')->cannotBeEmpty()->isRequired()->end()
135
                                ->scalarNode('template')->defaultValue('@FSiAdminSecurity/PasswordReset/mail.html.twig')->end()
136
                                ->scalarNode('reply_to')->defaultNull()->end()
137
                            ->end()
138
                        ->end()
139
                        ->arrayNode('change_password_form')
140
                            ->addDefaultsIfNotSet()
141
                            ->children()
142
                                ->scalarNode('type')->defaultValue(PasswordReset\ChangePasswordType::class)->end()
143
                                ->arrayNode('validation_groups')
144
                                    ->prototype('scalar')->end()
145
                                    ->defaultValue(['ResetPassword', 'Default'])
146
                                ->end()
147
                            ->end()
148
                        ->end()
149
                        ->arrayNode('request_form')
150
                            ->addDefaultsIfNotSet()
151
                            ->children()
152
                                ->scalarNode('type')->defaultValue(PasswordReset\RequestType::class)->end()
153
                            ->end()
154
                        ->end()
155
                    ->end()
156
                ->end()
157
                ->arrayNode('change_password')
158
                    ->addDefaultsIfNotSet()
159
                    ->children()
160
                        ->arrayNode('form')
161
                            ->addDefaultsIfNotSet()
162
                            ->children()
163
                                ->scalarNode('type')->defaultValue(ChangePasswordType::class)->end()
164
                                ->arrayNode('validation_groups')
165
                                    ->prototype('scalar')->end()
166
                                    ->defaultValue(['ChangePassword', 'Default'])
167
                                ->end()
168
                            ->end()
169
                        ->end()
170
                    ->end()
171
                ->end()
172
                ->arrayNode('templates')
173
                    ->addDefaultsIfNotSet()
174
                    ->children()
175
                        ->scalarNode('login')->defaultValue('@FSiAdminSecurity/Security/login.html.twig')->end()
176
                        ->scalarNode('change_password')->defaultValue('@FSiAdminSecurity/Admin/change_password.html.twig')->end()
177
                        ->arrayNode('activation')
178
                            ->addDefaultsIfNotSet()
179
                            ->children()
180
                                ->scalarNode('change_password')->defaultValue('@FSiAdminSecurity/Activation/change_password.html.twig')->end()
181
                            ->end()
182
                        ->end()
183
                        ->arrayNode('password_reset')
184
                            ->addDefaultsIfNotSet()
185
                            ->children()
186
                                ->scalarNode('request')->defaultValue('@FSiAdminSecurity/PasswordReset/request.html.twig')->end()
187
                                ->scalarNode('change_password')->defaultValue('@FSiAdminSecurity/PasswordReset/change_password.html.twig')->end()
188
                            ->end()
189
                        ->end()
190
                    ->end()
191
                ->end()
192
            ->end()
193
        ;
194
195
        return $treeBuilder;
196
    }
197
}
198