1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpAbac\Example; |
4
|
|
|
|
5
|
|
|
class User { |
6
|
|
|
/** @var int **/ |
7
|
|
|
private $id; |
8
|
|
|
/** @var string **/ |
9
|
|
|
private $name; |
10
|
|
|
/** @var int **/ |
11
|
|
|
private $age; |
12
|
|
|
/** @var string **/ |
13
|
|
|
private $parentNationality; |
14
|
|
|
/** @var array **/ |
15
|
|
|
private $visas; |
16
|
|
|
/** @var bool **/ |
17
|
|
|
private $hasDoneJapd; |
18
|
|
|
/** @var bool **/ |
19
|
|
|
private $hasDrivingLicense; |
20
|
|
|
/** @var string Iso code of user country */ |
21
|
|
|
private $country; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param int $id |
25
|
|
|
* @return \PhpAbac\Example\User |
26
|
|
|
*/ |
27
|
8 |
|
public function setId($id) { |
28
|
8 |
|
$this->id = $id; |
29
|
|
|
|
30
|
8 |
|
return $this; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return int |
35
|
|
|
*/ |
36
|
2 |
|
public function getId() { |
37
|
2 |
|
return $this->id; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $name |
42
|
|
|
* @return \PhpAbac\Example\User |
43
|
|
|
*/ |
44
|
6 |
|
public function setName($name) { |
45
|
6 |
|
$this->name = $name; |
46
|
|
|
|
47
|
6 |
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public function getName() { |
54
|
|
|
return $this->name; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param int $age |
59
|
|
|
* @return \PhpAbac\Example\User |
60
|
|
|
*/ |
61
|
8 |
|
public function setAge($age) { |
62
|
8 |
|
$this->age = $age; |
63
|
|
|
|
64
|
8 |
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return int |
69
|
|
|
*/ |
70
|
5 |
|
public function getAge() { |
71
|
5 |
|
return $this->age; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string $parentNationality |
76
|
|
|
* @return \PhpAbac\Example\User |
77
|
|
|
*/ |
78
|
7 |
|
public function setParentNationality($parentNationality) { |
79
|
7 |
|
$this->parentNationality = $parentNationality; |
80
|
|
|
|
81
|
7 |
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return bool |
86
|
|
|
*/ |
87
|
2 |
|
public function getParentNationality() { |
88
|
2 |
|
return $this->parentNationality; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param \PhpAbac\Example\Visa $visa |
93
|
|
|
* @return \PhpAbac\Example\User |
94
|
|
|
*/ |
95
|
6 |
|
public function addVisa(Visa $visa) { |
96
|
6 |
|
$this->visas[$visa->getId()] = $visa; |
97
|
|
|
|
98
|
6 |
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param \PhpAbac\Example\Visa $visa |
103
|
|
|
* @return \PhpAbac\Example\User |
104
|
|
|
*/ |
105
|
|
|
public function removeVisa(Visa $visa) { |
106
|
|
|
if(isset($this->visas[$visa->getId()])) { |
|
|
|
|
107
|
|
|
unset($this->visas[$visa->getId()]); |
108
|
|
|
} |
109
|
|
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
1 |
|
public function getVisas() { |
116
|
1 |
|
return $this->visas; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Return a specific visa |
121
|
|
|
* |
122
|
|
|
* @param Visa $visa |
|
|
|
|
123
|
|
|
* |
124
|
|
|
* @return mixed|null |
125
|
|
|
*/ |
126
|
2 |
|
public function getVisa($country_code) { |
127
|
|
|
/** @var Visa $visa */ |
128
|
2 |
|
$visas = []; |
129
|
2 |
|
foreach($this->visas as $visa) { |
|
|
|
|
130
|
2 |
|
if ($visa->getCountry()->getCode() == $country_code) |
|
|
|
|
131
|
2 |
|
$visas[] = $visa; |
132
|
2 |
|
} |
133
|
2 |
|
return $visas; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param bool $hasDoneJapd |
138
|
|
|
* @return \PhpAbac\Example\User |
139
|
|
|
*/ |
140
|
6 |
|
public function setHasDoneJapd($hasDoneJapd) { |
141
|
6 |
|
$this->hasDoneJapd = $hasDoneJapd; |
142
|
|
|
|
143
|
6 |
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return bool |
148
|
|
|
*/ |
149
|
1 |
|
public function getHasDoneJapd() { |
150
|
1 |
|
return $this->hasDoneJapd; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param bool $hasDrivingLicense |
155
|
|
|
* @return \PhpAbac\Example\User |
156
|
|
|
*/ |
157
|
6 |
|
public function setHasDrivingLicense($hasDrivingLicense) { |
158
|
6 |
|
$this->hasDrivingLicense = $hasDrivingLicense; |
159
|
|
|
|
160
|
6 |
|
return $this; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return bool |
165
|
|
|
*/ |
166
|
1 |
|
public function getHasDrivingLicense() { |
167
|
1 |
|
return $this->hasDrivingLicense; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Function to set the iso code of the user country |
173
|
|
|
* |
174
|
|
|
* @param $country |
175
|
|
|
*/ |
176
|
5 |
|
public function setCountry($country) { |
177
|
5 |
|
$this->country = $country; |
178
|
|
|
|
179
|
5 |
|
return $this; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @return string Iso code of the user country |
184
|
|
|
*/ |
185
|
1 |
|
public function getCountry() { |
186
|
1 |
|
return $this->country; |
187
|
|
|
} |
188
|
|
|
} |