-
Notifications
You must be signed in to change notification settings - Fork 61
/
NodeInterface.php
218 lines (198 loc) · 6.6 KB
/
NodeInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
/*
* (c) Markus Lanthaler <mail@markus-lanthaler.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ML\JsonLD;
/**
* A generic interface for nodes in a JSON-LD graph.
*
* @author Markus Lanthaler <mail@markus-lanthaler.com>
*/
interface NodeInterface
{
/**
* Get ID
*
* @return string|null The ID of the node or null.
*/
public function getId();
/**
* Set the node type
*
* @param null|NodeInterface|array[NodeInterface] The type(s) of this node.
*
* @return self
*
* @throws \InvalidArgumentException If type is not null, a Node or an
* array of Nodes.
*/
public function setType($type);
/**
* Add a type to this node
*
* @param NodeInterface The type to add.
*
* @return self
*/
public function addType(NodeInterface $type);
/**
* Remove a type from this node
*
* @param NodeInterface The type to remove.
*
* @return self
*/
public function removeType(NodeInterface $type);
/**
* Get node type
*
* @return null|NodeInterface|NodeInterface[] Returns the type(s) of this node.
*/
public function getType();
/**
* Get the nodes which have this node as their type
*
* This will return all nodes that link to this Node instance via the
* @type (rdf:type) property.
*
* @return NodeInterface[] Returns the node(s) having this node as their
* type.
*/
public function getNodesWithThisType();
/**
* Get the graph the node belongs to
*
* @return null|GraphInterface Returns the graph the node belongs to or
* null if the node doesn't belong to any graph.
*/
public function getGraph();
/**
* Removes the node from the graph
*
* This will also remove all references to and from other nodes in this
* node's graph.
*
* @return self
*/
public function removeFromGraph();
/**
* Is this node a blank node
*
* A blank node is a node whose identifier has just local meaning. It has
* therefore a node identifier with the prefix <code>_:</code> or no
* identifier at all.
*
* @return bool Returns true if the node is a blank node, otherwise false.
*/
public function isBlankNode();
/**
* Set a property of the node
*
* If the value is or contains a reference to a node which is not part
* of the graph, the referenced node will added to the graph as well.
* If the referenced node is already part of another graph a copy of the
* node will be created and added to the graph.
*
* @param string $property The name of the property.
* @param mixed $value The value of the property. This MUST NOT be
* an array. Use null to remove the property.
*
* @return self
*
* @throws \InvalidArgumentException If value is an array or an object
* which is neither a language-tagged
* string nor a typed value or a node.
*/
public function setProperty($property, $value);
/**
* Adds a value to a property of the node
*
* If the value already exists, it won't be added again, i.e., there
* won't be any duplicate property values.
*
* If the value is or contains a reference to a node which is not part
* of the graph, the referenced node will added to the graph as well.
* If the referenced node is already part of another graph a copy of the
* node will be created and added to the graph.
*
* @param string $property The name of the property.
* @param mixed $value The value of the property. This MUST NOT be
* an array.
*
* @return self
*
* @throws \InvalidArgumentException If value is an array or an object
* which is neither a language-tagged
* string nor a typed value or a node.
*/
public function addPropertyValue($property, $value);
/**
* Removes a property and all it's values
*
* @param string $property The name of the property to remove.
*
* @return self
*/
public function removeProperty($property);
/**
* Removes a property value
*
* @param string $property The name of the property.
* @param mixed $value The value of the property. This MUST NOT be
* an array.
*
* @return self
*/
public function removePropertyValue($property, $value);
/**
* Get the properties of this node
*
* @return array Returns an associative array containing all properties
* of this node. The key is the property name whereas the
* value is the property's value.
*/
public function getProperties();
/**
* Get the value of a property
*
* @param string $property The name of the property.
*
* @return mixed Returns the value of the property or null if the
* property doesn't exist.
*/
public function getProperty($property);
/**
* Get the reverse properties of this node
*
* @return array Returns an associative array containing all reverse
* properties of this node. The key is the property name
* whereas the value is an array of nodes linking to this
* instance via that property.
*/
public function getReverseProperties();
/**
* Get the nodes of a reverse property
*
* This will return all nodes that link to this Node instance via the
* specified property.
*
* @param string $property The name of the reverse property.
*
* @return null|NodeInterface|NodeInterface[] Returns the node(s) pointing
* to this instance via the specified
* property or null if no such node exists.
*/
public function getReverseProperty($property);
/**
* Compares this node object to the specified value.
*
* @param mixed $other The value this instance should be compared to.
*
* @return bool Returns true if the passed value is the same as this
* instance; false otherwise.
*/
public function equals(NodeInterface $other);
}