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\Model; |
13
|
|
|
|
14
|
|
|
use Tmilos\ScimSchema\ScimConstants; |
15
|
|
|
|
16
|
|
|
abstract class Schema extends Resource |
17
|
|
|
{ |
18
|
|
|
/** @var string */ |
19
|
|
|
protected $name; |
20
|
|
|
|
21
|
|
|
/** @var string */ |
22
|
|
|
protected $description; |
23
|
|
|
|
24
|
|
|
/** @var Schema\Attribute[] */ |
25
|
|
|
protected $attributes = []; |
26
|
|
|
|
27
|
|
|
public function getResourceType() |
28
|
|
|
{ |
29
|
|
|
return ScimConstants::RESOURCE_TYPE_SCHEMA; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
public function getName() |
36
|
|
|
{ |
37
|
|
|
return $this->name; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $name |
42
|
|
|
*/ |
43
|
|
|
public function setName($name) |
44
|
|
|
{ |
45
|
|
|
$this->name = $name; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
|
|
public function getDescription() |
52
|
|
|
{ |
53
|
|
|
return $this->description; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $description |
58
|
|
|
*/ |
59
|
|
|
public function setDescription($description) |
60
|
|
|
{ |
61
|
|
|
$this->description = $description; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param Schema\Attribute $attribute |
66
|
|
|
*/ |
67
|
|
|
public function addAttribute(Schema\Attribute $attribute) |
68
|
|
|
{ |
69
|
|
|
$this->attributes[] = $attribute; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return Schema\Attribute[] |
74
|
|
|
*/ |
75
|
|
|
public function getAttributes() |
76
|
|
|
{ |
77
|
|
|
return $this->attributes; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param string $name |
82
|
|
|
* |
83
|
|
|
* @return null|Schema\Attribute |
84
|
|
|
*/ |
85
|
|
|
public function findAttribute($name) |
86
|
|
|
{ |
87
|
|
|
foreach ($this->attributes as $attribute) { |
88
|
|
|
if ($attribute->getName() === $name) { |
89
|
|
|
return $attribute; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return null; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function serializeObject() |
97
|
|
|
{ |
98
|
|
|
$result = parent::serializeObject(); |
99
|
|
|
$result['name'] = $this->name; |
100
|
|
|
$result['description'] = $this->description; |
101
|
|
|
$result['attributes'] = []; |
102
|
|
|
foreach ($this->attributes as $attribute) { |
103
|
|
|
$result['attributes'][] = $attribute->serializeObject(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $result; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param array $data |
111
|
|
|
* |
112
|
|
|
* @return Schema |
113
|
|
|
*/ |
114
|
|
|
public static function deserializeObject(array $data) |
115
|
|
|
{ |
116
|
|
|
/** @var Schema $result */ |
117
|
|
|
$result = self::deserializeCommonAttributes($data); |
118
|
|
|
$result->name = $data['name']; |
119
|
|
|
$result->description = $data['description']; |
120
|
|
|
$result->attributes = []; |
121
|
|
|
foreach ($data['attributes'] as $attribute) { |
122
|
|
|
$result->attributes[] = Schema\Attribute::deserializeObject($attribute); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return $result; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|