1 | <?php declare(strict_types=1); |
||
10 | abstract class Container extends PrettyJsonSerializable implements \Countable, \ArrayAccess, \IteratorAggregate |
||
11 | { |
||
12 | protected $members = []; |
||
13 | protected $closed = true; |
||
14 | |||
15 | /** |
||
16 | * Check whether value can be added as member. |
||
17 | * |
||
18 | * @throws InvalidArgumentException if value is no JSKOS Resource |
||
19 | */ |
||
20 | protected static function checkMember($value) |
||
28 | |||
29 | /** |
||
30 | * Check whether an equal member alredy exists in this Container. |
||
31 | */ |
||
32 | protected function findMember($member) |
||
36 | |||
37 | /** |
||
38 | * Create a new container, possibly from an array. |
||
39 | */ |
||
40 | public function __construct(array $members = []) |
||
50 | |||
51 | /** |
||
52 | * Apply a function to each member of this container. |
||
53 | * @param $callback callable |
||
54 | */ |
||
55 | public function map(callable $callback): array |
||
65 | |||
66 | /** |
||
67 | * Return whether this container is empty (no members and closed). |
||
68 | */ |
||
69 | public function isEmpty(): bool |
||
73 | |||
74 | /** |
||
75 | * Return whether this container is closed. |
||
76 | */ |
||
77 | public function isClosed(): bool |
||
81 | |||
82 | /** |
||
83 | * Set whether this container is closed (no unknown members) or not. |
||
84 | * @param Boolean $closed |
||
85 | */ |
||
86 | public function setClosed(bool $closed = true) |
||
90 | |||
91 | # implements Countable |
||
92 | |||
93 | /** |
||
94 | * Return the number of known values in this container (closed or not). |
||
95 | */ |
||
96 | public function count(): int |
||
100 | |||
101 | # implements ArrayAccess: |
||
102 | |||
103 | /** |
||
104 | * Return whether an object exists at the given offset. |
||
105 | * @param mixed $offset |
||
106 | */ |
||
107 | public function offsetExists($offset) |
||
111 | |||
112 | /** |
||
113 | * Return an object at the given offset. |
||
114 | * @param mixed $offset |
||
115 | */ |
||
116 | public function offsetGet($offset) |
||
120 | |||
121 | /** |
||
122 | * Set an object at the given offset. |
||
123 | * @param mixed $offset |
||
124 | * @param mixed $object |
||
125 | */ |
||
126 | public function offsetSet($offset, $object) |
||
140 | |||
141 | /** |
||
142 | * Append an object at the end. |
||
143 | */ |
||
144 | public function append($object) |
||
152 | |||
153 | /** |
||
154 | * @throws \BadMethodCallException |
||
155 | */ |
||
156 | public function offsetUnset($key) |
||
160 | |||
161 | # implements IteratorAggregate: |
||
162 | |||
163 | /** |
||
164 | * Return an iterator to iterate all members of the set. |
||
165 | */ |
||
166 | public function getIterator() |
||
170 | |||
171 | # extends PrettyJsonSerializable: |
||
172 | |||
173 | /** |
||
174 | * Return a data structure to serialize this container as JSON. |
||
175 | */ |
||
176 | public function jsonLDSerialize(string $context=self::DEFAULT_CONTEXT) |
||
187 | } |
||
188 |