Issues (128)

src/DependencyInjection/Configuration.php (4 issues)

1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components Bundle Project
5
 *
6
 * (c) Daniel West <[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
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentsBundle\DependencyInjection;
15
16
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
17
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
18
use Symfony\Component\Config\Definition\ConfigurationInterface;
19
use Symfony\Component\HttpFoundation\Cookie;
20
21
/**
22
 * @author Daniel West <[email protected]>
23
 */
24
class Configuration implements ConfigurationInterface
25
{
26
    public function getConfigTreeBuilder(): TreeBuilder
27
    {
28
        $treeBuilder = new TreeBuilder('silverback_api_components');
29
        $rootNode = $treeBuilder->getRootNode();
30
        $rootNode
31
            ->children()
32
                ->scalarNode('website_name')->isRequired()->end()
33
                ->scalarNode('table_prefix')->defaultValue('_acb_')->end()
34
                ->scalarNode('metadata_key')->defaultValue('_metadata')->end()
35
            ->end();
36
37
        $this->addMercureNode($rootNode);
38
        $this->addRouteSecurityNode($rootNode);
39
        $this->addRoutableSecurityNode($rootNode);
40
        $this->addRefreshTokenNode($rootNode);
41
        $this->addPublishableNode($rootNode);
42
        $this->addEnabledComponentsNode($rootNode);
43
        $this->addUserNode($rootNode);
44
45
        return $treeBuilder;
46
    }
47
48
    private function addMercureNode(ArrayNodeDefinition $rootNode): void
49
    {
50
        $rootNode
51
            ->children()
52
                ->arrayNode('mercure')
53
                    ->addDefaultsIfNotSet()
54
                    ->children()
55
                        ->scalarNode('hub_name')->defaultNull()->end()
56
                        ->arrayNode('cookie')
0 ignored issues
show
The method arrayNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

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

56
                        ->/** @scrutinizer ignore-call */ arrayNode('cookie')
Loading history...
57
                            ->addDefaultsIfNotSet()
58
                            ->children()
59
                                 ->scalarNode('samesite')->defaultValue(Cookie::SAMESITE_STRICT)
60
                                ->end()
61
                            ->end()
62
                        ->end()
63
                    ->end()
64
                ->end()
65
            ->end();
66
    }
67
68
    private function addRouteSecurityNode(ArrayNodeDefinition $rootNode): void
69
    {
70
        $rootNode
71
            ->children()
72
                ->arrayNode('route_security')
73
                    ->arrayPrototype()
74
                        ->children()
75
                            ->scalarNode('route')->end()
76
                            ->scalarNode('security')->end()
0 ignored issues
show
The method scalarNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

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

76
                            ->/** @scrutinizer ignore-call */ scalarNode('security')->end()
Loading history...
77
                        ->end()
78
                    ->end()
79
                ->end()
80
            ->end();
81
    }
82
83
    private function addRoutableSecurityNode(ArrayNodeDefinition $rootNode): void
84
    {
85
        $rootNode
86
            ->children()
87
                ->scalarNode('routable_security')->defaultNull()->end()
88
            ->end();
0 ignored issues
show
The method end() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Symfony\Component\Config...ion\Builder\TreeBuilder. Are you sure you never get one of those? ( Ignorable by Annotation )

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

88
            ->/** @scrutinizer ignore-call */ end();
Loading history...
89
    }
90
91
    private function addRefreshTokenNode(ArrayNodeDefinition $rootNode): void
92
    {
93
        $rootNode
94
            ->children()
95
                ->arrayNode('refresh_token')
96
                    ->addDefaultsIfNotSet()
97
                    ->children()
98
                        ->scalarNode('handler_id')->cannotBeEmpty()->isRequired()->end()
99
                        ->arrayNode('options')
100
                            ->useAttributeAsKey('key')
101
                            ->prototype('variable')->end()
102
                        ->end()
103
                        ->scalarNode('cookie_name')->cannotBeEmpty()->isRequired()->end()
104
                        ->scalarNode('ttl')->cannotBeEmpty()->isRequired()->end()
105
                        ->scalarNode('database_user_provider')->cannotBeEmpty()->isRequired()->end()
106
                    ->end()
107
                ->end()
108
            ->end();
109
    }
110
111
    private function addPublishableNode(ArrayNodeDefinition $rootNode): void
112
    {
113
        $rootNode
114
            ->children()
115
                ->arrayNode('publishable')
116
                    ->addDefaultsIfNotSet()
117
                    ->children()
118
                        ->scalarNode('permission')->cannotBeEmpty()->isRequired()->end()
119
                    ->end()
120
                ->end()
121
            ->end();
122
    }
123
124
    private function addEnabledComponentsNode(ArrayNodeDefinition $rootNode): void
125
    {
126
        $rootNode
127
            ->children()
128
                ->arrayNode('enabled_components')
129
                    ->addDefaultsIfNotSet()
130
                    ->children()
131
                        ->booleanNode('form')->defaultValue(true)->end()
132
                        ->booleanNode('collection')->defaultValue(true)->end()
0 ignored issues
show
The method booleanNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

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

132
                        ->/** @scrutinizer ignore-call */ booleanNode('collection')->defaultValue(true)->end()
Loading history...
133
                    ->end()
134
                ->end()
135
            ->end();
136
    }
137
138
    private function addUserNode(ArrayNodeDefinition $rootNode): void
139
    {
140
        $rootNode
141
            ->children()
142
                ->arrayNode('user')
143
                    ->addDefaultsIfNotSet()
144
                    ->children()
145
                        ->scalarNode('class_name')
146
                            ->isRequired()
147
                        ->end()
148
                        ->arrayNode('email_verification')
149
                            ->canBeDisabled()
150
                            ->addDefaultsIfNotSet()
151
                            ->children()
152
                                ->arrayNode('email')
153
                                    ->children()
154
                                        ->scalarNode('redirect_path_query')->end()
155
                                        ->scalarNode('default_redirect_path')->isRequired()->end()
156
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Please verify your email')->end()
157
                                    ->end()
158
                                ->end()
159
                                ->booleanNode('default_value')->isRequired()->end()
160
                                ->booleanNode('verify_on_change')->isRequired()->end()
161
                                ->booleanNode('verify_on_register')->isRequired()->end()
162
                                ->booleanNode('deny_unverified_login')->isRequired()->end()
163
                            ->end()
164
                        ->end()
165
                        ->arrayNode('new_email_confirmation')
166
                            ->addDefaultsIfNotSet()
167
                            ->children()
168
                                ->arrayNode('email')
169
                                    ->children()
170
                                        ->scalarNode('redirect_path_query')->end()
171
                                        ->scalarNode('default_redirect_path')->isRequired()->end()
172
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Please confirm your new email address')->end()
173
                                    ->end()
174
                                ->end()
175
                                ->integerNode('request_timeout_seconds')->defaultValue(86400)->end()
176
                            ->end()
177
                        ->end()
178
                        ->arrayNode('password_reset')
179
                            ->addDefaultsIfNotSet()
180
                            ->children()
181
                                ->arrayNode('email')
182
                                    ->children()
183
                                        ->scalarNode('redirect_path_query')->end()
184
                                        ->scalarNode('default_redirect_path')->isRequired()->end()
185
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Your password has been reset')->end()
186
                                    ->end()
187
                                ->end()
188
                                ->integerNode('repeat_ttl_seconds')->defaultValue(8600)->end()
189
                                ->integerNode('request_timeout_seconds')->defaultValue(3600)->end()
190
                            ->end()
191
                        ->end()
192
                        ->arrayNode('emails')
193
                            ->addDefaultsIfNotSet()
194
                            ->children()
195
                                ->arrayNode('welcome')
196
                                    ->canBeDisabled()
197
                                    ->addDefaultsIfNotSet()
198
                                    ->children()
199
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Welcome to {{ website_name }}')->end()
200
                                    ->end()
201
                                ->end()
202
                                ->arrayNode('user_enabled')
203
                                    ->canBeDisabled()
204
                                    ->addDefaultsIfNotSet()
205
                                    ->children()
206
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Your account has been enabled')->end()
207
                                    ->end()
208
                                ->end()
209
                                ->arrayNode('username_changed')
210
                                    ->canBeDisabled()
211
                                    ->addDefaultsIfNotSet()
212
                                    ->children()
213
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Your username has been updated')->end()
214
                                    ->end()
215
                                ->end()
216
                                ->arrayNode('password_changed')
217
                                    ->canBeDisabled()
218
                                    ->addDefaultsIfNotSet()
219
                                    ->children()
220
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Your password has been changed')->end()
221
                                    ->end()
222
                                ->end()
223
                            ->end()
224
                        ->end()
225
                    ->end()
226
                ->end()
227
            ->end();
228
    }
229
}
230