1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This software may be modified and distributed under the terms |
7
|
|
|
* of the MIT license. See the LICENSE file for details. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace FAPI\Sylius\Model\Customer; |
11
|
|
|
|
12
|
|
|
use FAPI\Sylius\Model\CreatableFromArray; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author Kasim Taskin <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
final class Customer implements CreatableFromArray |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var int |
21
|
|
|
*/ |
22
|
|
|
private $id; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var User |
26
|
|
|
*/ |
27
|
|
|
private $user; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $email; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
private $emailCanonical; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $firstName; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
private $lastName; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
private $gender; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Customer constructor. |
56
|
|
|
*/ |
57
|
|
|
private function __construct( |
58
|
|
|
int $id, |
59
|
|
|
User $user, |
60
|
|
|
string $email, |
61
|
|
|
string $emailCanonical, |
62
|
|
|
string $firstName, |
63
|
|
|
string $lastName, |
64
|
|
|
string $gender |
65
|
|
|
) { |
66
|
|
|
$this->id = $id; |
67
|
|
|
if (-1 !== $user->getId()) { |
68
|
|
|
$this->user = $user; |
69
|
|
|
} |
70
|
|
|
$this->email = $email; |
71
|
|
|
$this->emailCanonical = $emailCanonical; |
72
|
|
|
$this->firstName = $firstName; |
73
|
|
|
$this->lastName = $lastName; |
74
|
|
|
$this->gender = $gender; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return Customer |
79
|
|
|
*/ |
80
|
|
|
public static function createFromArray(array $data): self |
81
|
|
|
{ |
82
|
|
|
$id = -1; |
83
|
|
|
if (isset($data['id'])) { |
84
|
|
|
$id = $data['id']; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$user = User::createFromArray([]); |
88
|
|
|
if (isset($data['user'])) { |
89
|
|
|
$user = User::createFromArray($data['user']); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$email = ''; |
93
|
|
|
if (isset($data['email'])) { |
94
|
|
|
$email = $data['email']; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$emailCanonical = ''; |
98
|
|
|
if (isset($data['emailCanonical'])) { |
99
|
|
|
$emailCanonical = $data['emailCanonical']; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$firstName = ''; |
103
|
|
|
if (isset($data['firstName'])) { |
104
|
|
|
$firstName = $data['firstName']; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$lastName = ''; |
108
|
|
|
if (isset($data['lastName'])) { |
109
|
|
|
$lastName = $data['lastName']; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$gender = ''; |
113
|
|
|
if (isset($data['gender'])) { |
114
|
|
|
$gender = $data['gender']; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return new self($id, $user, $email, $emailCanonical, $firstName, $lastName, $gender); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function getId(): int |
121
|
|
|
{ |
122
|
|
|
return $this->id; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function getUser(): User |
126
|
|
|
{ |
127
|
|
|
return $this->user; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function getEmail(): string |
131
|
|
|
{ |
132
|
|
|
return $this->email; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function getEmailCanonical(): string |
136
|
|
|
{ |
137
|
|
|
return $this->emailCanonical; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function getFirstName(): string |
141
|
|
|
{ |
142
|
|
|
return $this->firstName; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function getLastName(): string |
146
|
|
|
{ |
147
|
|
|
return $this->lastName; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function getGender(): string |
151
|
|
|
{ |
152
|
|
|
return $this->gender; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|