|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SDIS62\Core\User\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use libphonenumber\PhoneNumberUtil; |
|
6
|
|
|
use libphonenumber\PhoneNumberFormat; |
|
7
|
|
|
use SDIS62\Core\Common\Entity\IdentityTrait; |
|
8
|
|
|
use SDIS62\Core\User\Exception\InvalidProfileException; |
|
9
|
|
|
use SDIS62\Core\User\Exception\InvalidPhoneNumberException; |
|
10
|
|
|
|
|
11
|
|
|
abstract class Profile |
|
12
|
|
|
{ |
|
13
|
|
|
use IdentityTrait; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Utilisateur associé au profil |
|
17
|
|
|
* |
|
18
|
|
|
* @var SDIS62\Core\User\Entity\User |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $user; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Type du profil |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $phone_number; |
|
28
|
|
|
|
|
29
|
|
|
/* |
|
30
|
|
|
* Constructeur |
|
31
|
|
|
* |
|
32
|
|
|
* @param SDIS62\Core\User\Entity\User $user |
|
33
|
|
|
*/ |
|
34
|
126 |
|
public function __construct(User $user) |
|
35
|
|
|
{ |
|
36
|
126 |
|
$this->user = $user; |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
126 |
|
$user->addProfile($this); |
|
39
|
126 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Get the value of Type du profil |
|
43
|
|
|
* |
|
44
|
|
|
* @return string |
|
45
|
|
|
*/ |
|
46
|
15 |
|
final public function getType() |
|
47
|
|
|
{ |
|
48
|
15 |
|
if (empty($this->type)) { |
|
|
|
|
|
|
49
|
3 |
|
throw new InvalidProfileException(get_class($this).' doit avoir un $type'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
12 |
|
return $this->type; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Get the value of Numéro de téléphone concernant le profil |
|
57
|
|
|
* |
|
58
|
|
|
* @return \DateTime|null |
|
59
|
|
|
*/ |
|
60
|
3 |
|
public function getPhoneNumber() |
|
61
|
|
|
{ |
|
62
|
3 |
|
return $this->phone_number; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Set the value of Numéro de téléphone concernant le profil |
|
67
|
|
|
* |
|
68
|
|
|
* @param string|null professional_phone_number |
|
69
|
|
|
* @throws InvalidPhoneNumberException |
|
70
|
|
|
* |
|
71
|
|
|
* @return self |
|
72
|
|
|
*/ |
|
73
|
6 |
|
public function setPhoneNumber($phone_number) |
|
74
|
|
|
{ |
|
75
|
6 |
|
$phone_util = PhoneNumberUtil::getInstance(); |
|
76
|
6 |
|
$phone_number_parsed = $phone_util->parse($phone_number, "FR"); |
|
77
|
|
|
|
|
78
|
6 |
|
if (!$phone_util->isValidNumber($phone_number_parsed)) { |
|
79
|
3 |
|
throw new InvalidPhoneNumberException("Format du numéro de téléphone professionnel incorrect."); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
3 |
|
$this->phone_number = $phone_util->format($phone_number_parsed, PhoneNumberFormat::NATIONAL); |
|
83
|
|
|
|
|
84
|
3 |
|
return $this; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Get the value of Utilisateur associé au profil |
|
89
|
|
|
* |
|
90
|
|
|
* @return SDIS62\Core\User\Entity\User |
|
91
|
|
|
*/ |
|
92
|
21 |
|
public function getUser() |
|
93
|
|
|
{ |
|
94
|
21 |
|
return $this->user; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..