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\Util; |
15
|
|
|
|
16
|
|
|
use Doyo\UserBundle\Model\UserInterface; |
17
|
|
|
|
18
|
|
|
class CanonicalFieldsUpdater implements CanonicalFieldsUpdaterInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var CanonicalizerInterface |
22
|
|
|
*/ |
23
|
|
|
private $usernameCanonicalizer; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var CanonicalizerInterface |
27
|
|
|
*/ |
28
|
|
|
private $emailCanonicalizer; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* CanonicalFieldsUpdater constructor. |
32
|
|
|
*/ |
33
|
16 |
|
public function __construct(CanonicalizerInterface $usernameCanonicalizer, CanonicalizerInterface $emailCanonicalizer) |
34
|
|
|
{ |
35
|
16 |
|
$this->usernameCanonicalizer = $usernameCanonicalizer; |
36
|
16 |
|
$this->emailCanonicalizer = $emailCanonicalizer; |
37
|
|
|
} |
38
|
|
|
|
39
|
12 |
|
public function updateCanonicalFields(UserInterface $user) |
40
|
|
|
{ |
41
|
12 |
|
$user->setUsernameCanonical($this->usernameCanonicalizer->canonicalize($user->getUsername())); |
42
|
12 |
|
$user->setEmailCanonical($this->emailCanonicalizer->canonicalize($user->getEmail())); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Canonicalizes an email. |
47
|
|
|
* |
48
|
|
|
* @param string|null $email |
49
|
|
|
* |
50
|
|
|
* @return string|null |
51
|
|
|
*/ |
52
|
3 |
|
public function canonicalizeEmail($email) |
53
|
|
|
{ |
54
|
3 |
|
return $this->emailCanonicalizer->canonicalize($email); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Canonicalizes a username. |
59
|
|
|
* |
60
|
|
|
* @param string|null $username |
61
|
|
|
* |
62
|
|
|
* @return string|null |
63
|
|
|
*/ |
64
|
15 |
|
public function canonicalizeUsername($username) |
65
|
|
|
{ |
66
|
15 |
|
return $this->usernameCanonicalizer->canonicalize($username); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|