1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the "elao/api-resources-metadata" package. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) 2016 Elao |
7
|
|
|
* |
8
|
|
|
* @author Elao <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Elao\ApiResourcesMetadata\Resource; |
12
|
|
|
|
13
|
|
|
use Elao\ApiResourcesMetadata\Attribute\ResourceAttributeMetadata; |
14
|
|
|
|
15
|
|
|
final class ResourceMetadata |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
* |
20
|
|
|
* @internal Public in order to reduce the size of the class' serialized representation. |
21
|
|
|
*/ |
22
|
|
|
public $class; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
* |
27
|
|
|
* @internal Public in order to reduce the size of the class' serialized representation. |
28
|
|
|
*/ |
29
|
|
|
public $shortName; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
* |
34
|
|
|
* @internal Public in order to reduce the size of the class' serialized representation. |
35
|
|
|
*/ |
36
|
|
|
public $description; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var ResourceAttributeMetadata[] |
40
|
|
|
* |
41
|
|
|
* @internal Public in order to reduce the size of the class' serialized representation. |
42
|
|
|
*/ |
43
|
|
|
public $attributes; |
44
|
|
|
|
45
|
|
|
public function __construct(string $class) |
46
|
|
|
{ |
47
|
|
|
$this->class = $class; |
48
|
|
|
$this->shortName = ''; |
49
|
|
|
$this->description = ''; |
50
|
|
|
$this->attributes = []; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getClass(): string |
54
|
|
|
{ |
55
|
|
|
return $this->class; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getShortName(): string |
59
|
|
|
{ |
60
|
|
|
return $this->shortName; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function setShortName(string $shortName) |
64
|
|
|
{ |
65
|
|
|
$this->shortName = $shortName; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function getDescription(): string |
69
|
|
|
{ |
70
|
|
|
return $this->description; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function setDescription(string $description) |
74
|
|
|
{ |
75
|
|
|
$this->description = $description; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return ResourceAttributeMetadata[] |
80
|
|
|
*/ |
81
|
|
|
public function getAttributes(): array |
82
|
|
|
{ |
83
|
|
|
return $this->attributes; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function setAttributes(array $attributes) |
87
|
|
|
{ |
88
|
|
|
$this->attributes = $attributes; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param $name |
93
|
|
|
* |
94
|
|
|
* @return ResourceAttributeMetadata|null |
95
|
|
|
*/ |
96
|
|
|
public function getAttribute($name) |
97
|
|
|
{ |
98
|
|
|
return $this->attributes[$name] ?? null; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function addAttribute(ResourceAttributeMetadata $attribute) |
102
|
|
|
{ |
103
|
|
|
$this->attributes[$attribute->getName()] = $attribute; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Returns the names of the properties that should be serialized. |
108
|
|
|
* |
109
|
|
|
* @return string[] |
110
|
|
|
*/ |
111
|
|
|
public function __sleep() |
112
|
|
|
{ |
113
|
|
|
return [ |
114
|
|
|
'class', |
115
|
|
|
'shortName', |
116
|
|
|
'description', |
117
|
|
|
'attributes', |
118
|
|
|
]; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|