1 | <?php |
||
52 | class Thing implements ThingInterface |
||
53 | { |
||
54 | /** |
||
55 | * Resource types |
||
56 | * |
||
57 | * @var TypeInterface[] |
||
58 | */ |
||
59 | protected $types; |
||
60 | /** |
||
61 | * Resource ID |
||
62 | * |
||
63 | * @var string|null |
||
64 | */ |
||
65 | protected $resourceId = null; |
||
66 | /** |
||
67 | * Property |
||
68 | * |
||
69 | * @var PropertyList |
||
70 | */ |
||
71 | protected $properties; |
||
72 | |||
73 | /** |
||
74 | * Thing constructor |
||
75 | * |
||
76 | * @param TypeInterface|TypeInterface[] $types Type(s) |
||
77 | * @param null|string $resourceId Resource id |
||
78 | */ |
||
79 | 33 | public function __construct($types, $resourceId = null) |
|
80 | { |
||
81 | 33 | if (!is_array($types)) { |
|
82 | 31 | $types = [$types]; |
|
83 | 31 | } |
|
84 | |||
85 | // Run through all given types |
||
86 | 33 | foreach ($types as $type) { |
|
87 | 32 | if (!($type instanceof TypeInterface)) { |
|
88 | 1 | throw new RuntimeException( |
|
89 | 1 | sprintf(RuntimeException::INVALID_TYPE_STR, gettype($type)), |
|
90 | RuntimeException::INVALID_TYPE |
||
91 | 1 | ); |
|
92 | } |
||
93 | 32 | } |
|
94 | |||
95 | 32 | $this->types = $types; |
|
96 | 32 | $this->resourceId = $resourceId; |
|
97 | 32 | $this->properties = new PropertyList(); |
|
98 | 32 | } |
|
99 | |||
100 | /** |
||
101 | * Return the resource types |
||
102 | * |
||
103 | * @return TypeInterface[] Resource types |
||
104 | */ |
||
105 | 13 | public function getTypes() |
|
109 | |||
110 | /** |
||
111 | * Return the resource ID |
||
112 | * |
||
113 | * @return null|string Resource ID |
||
114 | */ |
||
115 | 13 | public function getResourceId() |
|
119 | |||
120 | /** |
||
121 | * Add a property value |
||
122 | * |
||
123 | * @param PropertyInterface $property Property |
||
124 | * @return Thing Self reference |
||
125 | */ |
||
126 | 12 | public function addProperty(PropertyInterface $property) |
|
131 | |||
132 | /** |
||
133 | * Return all properties |
||
134 | * |
||
135 | * @return PropertyList Properties |
||
136 | */ |
||
137 | 13 | public function getProperties() |
|
141 | |||
142 | /** |
||
143 | * Return the values of a single property |
||
144 | * |
||
145 | * @param string $name Property name |
||
146 | * @param VocabularyInterface $vocabulary Vocabulary |
||
147 | * @return array Property values |
||
148 | */ |
||
149 | 4 | public function getProperty($name, VocabularyInterface $vocabulary) |
|
154 | } |
||
155 |