1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Superdesk Web Publisher User Bundle. |
7
|
|
|
* |
8
|
|
|
* Copyright 2021 Sourcefabric z.ú. and contributors. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please see the |
11
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
12
|
|
|
* |
13
|
|
|
* @Copyright 2021 Sourcefabric z.ú |
14
|
|
|
* @license http://www.superdesk.org/license |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace SWP\Bundle\UserBundle\DependencyInjection; |
18
|
|
|
|
19
|
|
|
use SWP\Bundle\StorageBundle\Doctrine\ORM\EntityRepository; |
20
|
|
|
use SWP\Bundle\UserBundle\Form\RegistrationFormType; |
21
|
|
|
use SWP\Bundle\UserBundle\Model\ResetPasswordRequest; |
22
|
|
|
use SWP\Bundle\UserBundle\Model\User; |
23
|
|
|
use SWP\Bundle\UserBundle\Model\UserInterface; |
24
|
|
|
use SWP\Component\Storage\Factory\Factory; |
25
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
26
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
27
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* This is the class that validates and merges configuration from your app/config files. |
31
|
|
|
* |
32
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} |
33
|
|
|
*/ |
34
|
|
|
class Configuration implements ConfigurationInterface |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
|
|
public function getConfigTreeBuilder() |
40
|
|
|
{ |
41
|
|
|
$treeBuilder = new TreeBuilder('swp_user'); |
42
|
|
|
$treeBuilder->getRootNode() |
|
|
|
|
43
|
|
|
->children() |
44
|
|
|
->arrayNode('from_email') |
45
|
|
|
->isRequired() |
46
|
|
|
->children() |
47
|
|
|
->scalarNode('address')->isRequired()->cannotBeEmpty()->end() |
48
|
|
|
->scalarNode('sender_name')->isRequired()->cannotBeEmpty()->end() |
49
|
|
|
->end() |
50
|
|
|
->end() |
51
|
|
|
->arrayNode('persistence') |
52
|
|
|
->addDefaultsIfNotSet() |
53
|
|
|
->children() |
54
|
|
|
->arrayNode('orm') |
55
|
|
|
->addDefaultsIfNotSet() |
56
|
|
|
->canBeEnabled() |
57
|
|
|
->children() |
58
|
|
|
->arrayNode('classes') |
59
|
|
|
->addDefaultsIfNotSet() |
60
|
|
|
->children() |
61
|
|
|
->arrayNode('user') |
62
|
|
|
->addDefaultsIfNotSet() |
63
|
|
|
->children() |
64
|
|
|
->scalarNode('model')->cannotBeEmpty()->defaultValue(User::class)->end() |
65
|
|
|
->scalarNode('repository')->defaultValue(EntityRepository::class)->end() |
66
|
|
|
->scalarNode('factory')->defaultValue(Factory::class)->end() |
67
|
|
|
->scalarNode('interface')->defaultValue(UserInterface::class)->end() |
68
|
|
|
->scalarNode('object_manager_name')->defaultValue(null)->end() |
69
|
|
|
->end() |
70
|
|
|
->end() |
71
|
|
|
->arrayNode('reset_password_request') |
72
|
|
|
->addDefaultsIfNotSet() |
73
|
|
|
->children() |
74
|
|
|
->scalarNode('model')->cannotBeEmpty()->defaultValue(ResetPasswordRequest::class)->end() |
75
|
|
|
->scalarNode('repository')->defaultValue(EntityRepository::class)->end() |
76
|
|
|
->scalarNode('factory')->defaultValue(Factory::class)->end() |
77
|
|
|
->scalarNode('interface')->defaultValue(UserInterface::class)->end() |
78
|
|
|
->scalarNode('object_manager_name')->defaultValue(null)->end() |
79
|
|
|
->end() |
80
|
|
|
->end() |
81
|
|
|
->end() // classes |
82
|
|
|
->end() |
83
|
|
|
->end() |
84
|
|
|
->end() |
85
|
|
|
->end() |
86
|
|
|
->end() |
87
|
|
|
; |
88
|
|
|
|
89
|
|
|
$this->addRegistrationSection($treeBuilder->getRootNode()); |
|
|
|
|
90
|
|
|
|
91
|
|
|
return $treeBuilder; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
private function addRegistrationSection(ArrayNodeDefinition $node) |
95
|
|
|
{ |
96
|
|
|
$node |
97
|
|
|
->children() |
98
|
|
|
->arrayNode('registration') |
99
|
|
|
->addDefaultsIfNotSet() |
100
|
|
|
->canBeUnset() |
101
|
|
|
->children() |
102
|
|
|
->arrayNode('confirmation') |
103
|
|
|
->addDefaultsIfNotSet() |
104
|
|
|
->children() |
105
|
|
|
->booleanNode('enabled')->defaultFalse()->end() |
106
|
|
|
->scalarNode('template')->defaultValue('@SWPUser/Registration/confirmation_email.html.twig')->end() |
107
|
|
|
->arrayNode('from_email') |
108
|
|
|
->canBeUnset() |
109
|
|
|
->children() |
110
|
|
|
->scalarNode('address')->isRequired()->cannotBeEmpty()->end() |
111
|
|
|
->scalarNode('sender_name')->isRequired()->cannotBeEmpty()->end() |
112
|
|
|
->end() |
113
|
|
|
->end() |
114
|
|
|
->end() |
115
|
|
|
->end() |
116
|
|
|
->arrayNode('form') |
117
|
|
|
->addDefaultsIfNotSet() |
118
|
|
|
->children() |
119
|
|
|
->scalarNode('type')->defaultValue(RegistrationFormType::class)->end() |
120
|
|
|
->scalarNode('name')->defaultValue('swp_user_registration_form')->end() |
121
|
|
|
->arrayNode('validation_groups') |
122
|
|
|
->prototype('scalar')->end() |
123
|
|
|
->defaultValue(['Registration', 'Default']) |
124
|
|
|
->end() |
125
|
|
|
->end() |
126
|
|
|
->end() |
127
|
|
|
->end() |
128
|
|
|
->end() |
129
|
|
|
->end(); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: