1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the tmilos/scim-schema package. |
5
|
|
|
* |
6
|
|
|
* (c) Milos Tomic <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Tmilos\ScimSchema\Builder; |
13
|
|
|
|
14
|
|
|
use Tmilos\ScimSchema\Model\Schema\Attribute; |
15
|
|
|
use Tmilos\ScimSchema\ScimConstants; |
16
|
|
|
|
17
|
|
|
class AttributeBuilder |
18
|
|
|
{ |
19
|
|
|
/** @var string */ |
20
|
|
|
protected $name; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
protected $type; |
24
|
|
|
|
25
|
|
|
/** @var bool */ |
26
|
|
|
protected $multiValued = false; |
27
|
|
|
|
28
|
|
|
/** @var bool */ |
29
|
|
|
protected $required = false; |
30
|
|
|
|
31
|
|
|
/** @var string */ |
32
|
|
|
protected $description; |
33
|
|
|
|
34
|
|
|
/** @var Attribute[] */ |
35
|
|
|
protected $subAttributes = []; |
36
|
|
|
|
37
|
|
|
/** @var string[] */ |
38
|
|
|
protected $canonicalValues = []; |
39
|
|
|
|
40
|
|
|
/** @var bool */ |
41
|
|
|
protected $caseExact = false; |
42
|
|
|
|
43
|
|
|
/** @var string */ |
44
|
|
|
protected $mutability; |
45
|
|
|
|
46
|
|
|
/** @var string */ |
47
|
|
|
protected $returned; |
48
|
|
|
|
49
|
|
|
/** @var string */ |
50
|
|
|
protected $uniqueness; |
51
|
|
|
|
52
|
|
|
/** @var string[] */ |
53
|
|
|
protected $referenceTypes = []; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $name |
57
|
|
|
* @param string $type |
58
|
|
|
* @param string $description |
59
|
|
|
* |
60
|
|
|
* @return AttributeBuilder |
61
|
|
|
*/ |
62
|
|
|
public static function create($name, $type, $description = null) |
63
|
|
|
{ |
64
|
|
|
$result = new static(); |
65
|
|
|
$result->name = $name; |
66
|
|
|
$result->type = $type; |
67
|
|
|
$result->description = $description; |
68
|
|
|
|
69
|
|
|
return $result; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
protected function __construct() |
73
|
|
|
{ |
74
|
|
|
$this->mutability = ScimConstants::MUTABILITY_READ_WRITE; |
75
|
|
|
$this->returned = ScimConstants::RETURNED_DEFAULT; |
76
|
|
|
$this->uniqueness = ScimConstants::UNIQUENESS_NONE; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return Attribute |
81
|
|
|
*/ |
82
|
|
|
public function getAttribute() |
83
|
|
|
{ |
84
|
|
|
return new Attribute($this->name, $this->type, $this->multiValued, $this->required, $this->description, $this->subAttributes, |
85
|
|
|
$this->canonicalValues, $this->caseExact, $this->mutability, $this->returned, $this->uniqueness, $this->referenceTypes); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param bool $multiValued |
90
|
|
|
* |
91
|
|
|
* @return AttributeBuilder |
92
|
|
|
*/ |
93
|
|
|
public function setMultiValued($multiValued) |
94
|
|
|
{ |
95
|
|
|
$this->multiValued = (bool) $multiValued; |
96
|
|
|
|
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param bool $required |
102
|
|
|
* |
103
|
|
|
* @return AttributeBuilder |
104
|
|
|
*/ |
105
|
|
|
public function setRequired($required) |
106
|
|
|
{ |
107
|
|
|
$this->required = (bool) $required; |
108
|
|
|
|
109
|
|
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param string $description |
114
|
|
|
* |
115
|
|
|
* @return AttributeBuilder |
116
|
|
|
*/ |
117
|
|
|
public function setDescription($description) |
118
|
|
|
{ |
119
|
|
|
$this->description = (string) $description; |
120
|
|
|
|
121
|
|
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param bool $caseExact |
126
|
|
|
* |
127
|
|
|
* @return AttributeBuilder |
128
|
|
|
*/ |
129
|
|
|
public function setCaseExact($caseExact) |
130
|
|
|
{ |
131
|
|
|
$this->caseExact = (bool) $caseExact; |
132
|
|
|
|
133
|
|
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param string $mutability |
138
|
|
|
* |
139
|
|
|
* @return AttributeBuilder |
140
|
|
|
*/ |
141
|
|
|
public function setMutability($mutability) |
142
|
|
|
{ |
143
|
|
|
$this->mutability = $mutability; |
144
|
|
|
|
145
|
|
|
return $this; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param string $returned |
150
|
|
|
* |
151
|
|
|
* @return AttributeBuilder |
152
|
|
|
*/ |
153
|
|
|
public function setReturned($returned) |
154
|
|
|
{ |
155
|
|
|
$this->returned = $returned; |
156
|
|
|
|
157
|
|
|
return $this; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param string $uniqueness |
162
|
|
|
* |
163
|
|
|
* @return AttributeBuilder |
164
|
|
|
*/ |
165
|
|
|
public function setUniqueness($uniqueness) |
166
|
|
|
{ |
167
|
|
|
$this->uniqueness = $uniqueness; |
168
|
|
|
|
169
|
|
|
return $this; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param Attribute $attribute |
174
|
|
|
* |
175
|
|
|
* @return AttributeBuilder |
176
|
|
|
*/ |
177
|
|
|
public function addSubAttribute(Attribute $attribute) |
178
|
|
|
{ |
179
|
|
|
$this->subAttributes[] = $attribute; |
180
|
|
|
|
181
|
|
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @param Attribute[] $attributes |
186
|
|
|
* |
187
|
|
|
* @return AttributeBuilder |
188
|
|
|
*/ |
189
|
|
|
public function addSubAttributes(array $attributes) |
190
|
|
|
{ |
191
|
|
|
foreach ($attributes as $attribute) { |
192
|
|
|
$this->addSubAttribute($attribute); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
return $this; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param \string[] $canonicalValues |
200
|
|
|
* |
201
|
|
|
* @return AttributeBuilder |
202
|
|
|
*/ |
203
|
|
|
public function setCanonicalValues(array $canonicalValues) |
204
|
|
|
{ |
205
|
|
|
$this->canonicalValues = $canonicalValues; |
206
|
|
|
|
207
|
|
|
return $this; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @param \string[] $referenceTypes |
212
|
|
|
* |
213
|
|
|
* @return AttributeBuilder |
214
|
|
|
*/ |
215
|
|
|
public function setReferenceTypes(array $referenceTypes) |
216
|
|
|
{ |
217
|
|
|
$this->referenceTypes = []; |
218
|
|
|
foreach ($referenceTypes as $referenceType) { |
219
|
|
|
$this->addReferenceType($referenceType); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
return $this; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @param string $referenceType |
227
|
|
|
* |
228
|
|
|
* @return AttributeBuilder |
229
|
|
|
*/ |
230
|
|
|
public function addReferenceType($referenceType) |
231
|
|
|
{ |
232
|
|
|
$this->referenceTypes[] = $referenceType; |
233
|
|
|
|
234
|
|
|
return $this; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @param string $canonicalValue |
239
|
|
|
* |
240
|
|
|
* @return AttributeBuilder |
241
|
|
|
*/ |
242
|
|
|
public function addCanonicalValue($canonicalValue) |
243
|
|
|
{ |
244
|
|
|
$this->canonicalValues[] = (string) $canonicalValue; |
245
|
|
|
|
246
|
|
|
return $this; |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
|