1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Service; |
4
|
|
|
|
5
|
|
|
use App\Entity\User; |
6
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
7
|
|
|
use DomainException; |
8
|
|
|
use Ds\Component\Api\Api\Api; |
|
|
|
|
9
|
|
|
use Ds\Component\Api\Model\Individual; |
|
|
|
|
10
|
|
|
use Ds\Component\Api\Model\IndividualPersona; |
|
|
|
|
11
|
|
|
use Ds\Component\Api\Model\Organization; |
|
|
|
|
12
|
|
|
use Ds\Component\Api\Model\OrganizationPersona; |
|
|
|
|
13
|
|
|
use Ds\Component\Entity\Service\EntityService; |
|
|
|
|
14
|
|
|
use Ds\Component\Security\Model\Identity; |
|
|
|
|
15
|
|
|
use FOS\UserBundle\Model\UserManagerInterface; |
|
|
|
|
16
|
|
|
use LogicException; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class UserService |
20
|
|
|
*/ |
21
|
|
|
final class UserService extends EntityService |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var \FOS\UserBundle\Model\UserManagerInterface |
25
|
|
|
*/ |
26
|
|
|
private $customManager; # region accessor |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Get custom manager |
30
|
|
|
* |
31
|
|
|
* @return \FOS\UserBundle\Model\UserManagerInterface |
32
|
|
|
*/ |
33
|
|
|
public function getCustomManager() |
34
|
|
|
{ |
35
|
|
|
return $this->customManager; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
# endregion |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var \Ds\Component\Api\Api\Api |
42
|
|
|
*/ |
43
|
|
|
private $api; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Constructor |
47
|
|
|
* |
48
|
|
|
* @param \Doctrine\ORM\EntityManagerInterface $manager |
49
|
|
|
* @param \FOS\UserBundle\Model\UserManagerInterface $customManager |
50
|
|
|
* @param \Ds\Component\Api\Api\Api $api |
51
|
|
|
* @param string $entity |
52
|
|
|
*/ |
53
|
|
|
public function __construct(EntityManagerInterface $manager, UserManagerInterface $customManager, Api $api, string $entity = User::class) |
54
|
|
|
{ |
55
|
|
|
parent::__construct($manager, $entity); |
56
|
|
|
$this->customManager = $customManager; |
57
|
|
|
$this->api = $api; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Create identity for a user |
62
|
|
|
* |
63
|
|
|
* @param \App\Entity\User $user |
64
|
|
|
* @return \App\Entity\User |
65
|
|
|
* @throws \LogicException |
66
|
|
|
*/ |
67
|
|
|
public function createIdentity(User $user) |
68
|
|
|
{ |
69
|
|
|
if ($user->getIdentityUuid()) { |
70
|
|
|
throw new LogicException('Identity "'.$user->getIdentityUuid().'" already exists.'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
switch ($user->getIdentity()) { |
74
|
|
|
case Identity::INDIVIDUAL: |
75
|
|
|
$identity = new Individual; |
76
|
|
|
$identity |
77
|
|
|
->setOwner($user->getOwner()) |
78
|
|
|
->setOwnerUuid($user->getOwnerUuid()); |
79
|
|
|
$identity = $this->api->get('identities.individual')->create($identity); |
80
|
|
|
$persona = new IndividualPersona; |
81
|
|
|
$persona |
82
|
|
|
->setOwner($user->getOwner()) |
83
|
|
|
->setOwnerUuid($user->getOwnerUuid()) |
84
|
|
|
->setIndividual($identity) |
85
|
|
|
->setTitle([ // @todo remove hard-coded titles |
86
|
|
|
'en' => 'Default', |
87
|
|
|
'fr' => 'Défaut' |
88
|
|
|
]) |
89
|
|
|
->setData($user->getRegistration()->getData()); |
90
|
|
|
$this->api->get('identities.individual_persona')->create($persona); |
91
|
|
|
break; |
92
|
|
|
|
93
|
|
|
case Identity::ORGANIZATION: |
94
|
|
|
$identity = new Organization; |
95
|
|
|
$identity |
96
|
|
|
->setOwner($user->getOwner()) |
97
|
|
|
->setOwnerUuid($user->getOwnerUuid()); |
98
|
|
|
$identity = $this->api->get('identities.organization')->create($identity); |
99
|
|
|
|
100
|
|
|
$persona = new OrganizationPersona; |
101
|
|
|
$persona |
102
|
|
|
->setOwner($user->getOwner()) |
103
|
|
|
->setOwnerUuid($user->getOwnerUuid()) |
104
|
|
|
->setOrganization($identity) |
105
|
|
|
->setTitle([ // @todo remove hard-coded titles |
106
|
|
|
'en' => 'Default', |
107
|
|
|
'fr' => 'Défaut' |
108
|
|
|
]) |
109
|
|
|
->setData($user->getRegistration()->getData()); |
110
|
|
|
$this->api->get('identities.organization_persona')->create($persona); |
111
|
|
|
break; |
112
|
|
|
|
113
|
|
|
default: |
114
|
|
|
throw new DomainException('User identity "'.$user->getIdentity().'" is not supported.'); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$user->setIdentityUuid($identity->getUuid()); |
118
|
|
|
$this->customManager->updateUser($user); |
119
|
|
|
|
120
|
|
|
return $identity; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths