1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the DoyoUserBundle project. |
5
|
|
|
* |
6
|
|
|
* (c) Anthonius Munthi <[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 Doyo\UserBundle\Bridge\ORM; |
15
|
|
|
|
16
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
17
|
|
|
use Doctrine\Common\Persistence\ObjectRepository; |
18
|
|
|
use Doyo\UserBundle\Manager\AbstractUserManager; |
19
|
|
|
use Doyo\UserBundle\Model\UserInterface; |
20
|
|
|
use Doyo\UserBundle\Util\CanonicalFieldsUpdaterInterface; |
21
|
|
|
use Doyo\UserBundle\Util\PasswordUpdaterInterface; |
22
|
|
|
|
23
|
|
|
class UserManager extends AbstractUserManager |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var ObjectManager |
27
|
|
|
*/ |
28
|
|
|
private $objectManager; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $class; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* UserManager constructor. |
37
|
|
|
* |
38
|
|
|
* @param string $class |
39
|
|
|
*/ |
40
|
13 |
|
public function __construct( |
41
|
|
|
PasswordUpdaterInterface $passwordUpdater, |
42
|
|
|
CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater, |
43
|
|
|
ObjectManager $manager, |
44
|
|
|
$class |
45
|
|
|
) { |
46
|
13 |
|
$this->objectManager = $manager; |
47
|
13 |
|
$this->class = $class; |
48
|
13 |
|
parent::__construct($passwordUpdater, $canonicalFieldsUpdater); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
1 |
|
public function deleteUser(UserInterface $user) |
55
|
|
|
{ |
56
|
1 |
|
$this->objectManager->remove($user); |
57
|
1 |
|
$this->objectManager->flush(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
22 |
|
public function getClass() |
64
|
|
|
{ |
65
|
22 |
|
if (false !== strpos($this->class, ':')) { |
66
|
1 |
|
$metadata = $this->objectManager->getClassMetadata($this->class); |
67
|
1 |
|
$this->class = $metadata->getName(); |
68
|
|
|
} |
69
|
|
|
|
70
|
22 |
|
return $this->class; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
19 |
|
public function findUserBy(array $criteria) |
77
|
|
|
{ |
78
|
19 |
|
return $this->getRepository()->findOneBy($criteria); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
1 |
|
public function findUsers() |
85
|
|
|
{ |
86
|
1 |
|
return $this->getRepository()->findAll(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
1 |
|
public function reloadUser(UserInterface $user) |
93
|
|
|
{ |
94
|
1 |
|
$this->objectManager->refresh($user); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritdoc} |
99
|
|
|
*/ |
100
|
12 |
|
public function updateUser(UserInterface $user, $andFlush = true) |
101
|
|
|
{ |
102
|
12 |
|
$this->updateCanonicalFields($user); |
103
|
12 |
|
$this->updatePassword($user); |
104
|
|
|
|
105
|
12 |
|
$this->objectManager->persist($user); |
106
|
12 |
|
if ($andFlush) { |
107
|
12 |
|
$this->objectManager->flush(); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return ObjectRepository |
113
|
|
|
*/ |
114
|
20 |
|
protected function getRepository() |
115
|
|
|
{ |
116
|
20 |
|
return $this->objectManager->getRepository($this->getClass()); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|