1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the BenGorUserBundle bundle. |
5
|
|
|
* |
6
|
|
|
* (c) Beñat Espiña <[email protected]> |
7
|
|
|
* (c) Gorka Laucirica <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace BenGor\UserBundle\DependencyInjection\Compiler\Application\Service; |
14
|
|
|
|
15
|
|
|
use BenGor\UserBundle\Application\Service\LogInUserService; |
16
|
|
|
use BenGor\UserBundle\Security\FormLoginAuthenticator; |
17
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Log in user service builder. |
21
|
|
|
* |
22
|
|
|
* @author Beñat Espiña <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class LogInUserServiceBuilder extends ServiceBuilder |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
View Code Duplication |
public function register($user) |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
$this->container->setDefinition( |
32
|
|
|
$this->definitionName($user), |
33
|
|
|
new Definition( |
34
|
|
|
LogInUserService::class, [ |
35
|
|
|
$this->container->getDefinition( |
36
|
|
|
'bengor.user.infrastructure.persistence.' . $user . '_repository' |
37
|
|
|
), |
38
|
|
|
$this->container->getDefinition( |
39
|
|
|
'bengor.user.infrastructure.security.symfony.' . $user . '_password_encoder' |
40
|
|
|
), |
41
|
|
|
$this->container->getDefinition( |
42
|
|
|
'bengor.user.application.data_transformer.user_no_transformation' |
43
|
|
|
), |
44
|
|
|
] |
45
|
|
|
) |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$this->registerFormLoginAuthenticator($user); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
protected function definitionName($user) |
55
|
|
|
{ |
56
|
|
|
return 'bengor.user.application.service.log_in_' . $user; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
|
|
protected function aliasDefinitionName($user) |
63
|
|
|
{ |
64
|
|
|
return 'bengor_user.log_in_' . $user; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Registers the form login authenticator. |
69
|
|
|
* |
70
|
|
|
* This declaration should be in SecurityServicesCompilerPass file |
71
|
|
|
* but it requires the "bengor.user.application.service.log_in_user". |
72
|
|
|
* |
73
|
|
|
* @param string $user The user name |
74
|
|
|
*/ |
75
|
|
|
private function registerFormLoginAuthenticator($user) |
76
|
|
|
{ |
77
|
|
|
$routes = $this->configuration['routes'][$user]; |
78
|
|
|
|
79
|
|
|
$this->container->setDefinition( |
80
|
|
|
'bengor.user_bundle.security.form_login_' . $user . '_authenticator', |
81
|
|
|
new Definition( |
82
|
|
|
FormLoginAuthenticator::class, [ |
83
|
|
|
$this->container->getDefinition('bengor.user.infrastructure.routing.symfony_url_generator'), |
84
|
|
|
$this->container->getDefinition('bengor.user.application.service.log_in_' . $user), |
85
|
|
|
[ |
86
|
|
|
'login' => $routes['login']['name'], |
87
|
|
|
'login_check' => $routes['login_check']['name'], |
88
|
|
|
'success_redirection_route' => $routes['success_redirection_route'], |
89
|
|
|
], |
90
|
|
|
] |
91
|
|
|
) |
92
|
|
|
)->setPublic(false); |
93
|
|
|
|
94
|
|
|
$this->container->setAlias( |
95
|
|
|
'bengor_user.form_login_' . $user . '_authenticator', |
96
|
|
|
'bengor.user_bundle.security.form_login_' . $user . '_authenticator' |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.