1 | <?php |
||
21 | class FileStorageIndex |
||
22 | { |
||
23 | use AccessorTrait; |
||
24 | |||
25 | const MATCH_BY_KEY = 1; |
||
26 | const MATCH_BY_ID = 2; |
||
27 | const MATCH_BY_UUID = 3; |
||
28 | const MATCH_BY_HASH = 4; |
||
29 | |||
30 | /** |
||
31 | * Resolves matching type. |
||
32 | * |
||
33 | * @param IndexKey|int|string $key_or_id_or_uuid_or_hash A {@link IndexKey}, a node |
||
34 | * identifier, a v4 UUID, or a hash. |
||
35 | * |
||
36 | * @return int |
||
37 | * |
||
38 | * @throws \InvalidArgumentException if `$key_or_id_or_uuid_or_hash` is not one of |
||
39 | * the required type. |
||
40 | */ |
||
41 | static private function resolve_matching_type($key_or_id_or_uuid_or_hash) |
||
65 | |||
66 | /** |
||
67 | * Root directory including a trailing `DIRECTORY_SEPARATOR`. |
||
68 | * |
||
69 | * @var string |
||
70 | */ |
||
71 | private $root; |
||
72 | |||
73 | protected function get_root() |
||
77 | |||
78 | /** |
||
79 | * @param string $root FileStorageIndex root directory. |
||
80 | */ |
||
81 | public function __construct($root) |
||
85 | |||
86 | /** |
||
87 | * Adds a key to the index. |
||
88 | * |
||
89 | * Composite keys using the same `uid` or `uuid` are replaced by this one. |
||
90 | * |
||
91 | * @param IndexKey $key |
||
92 | */ |
||
93 | public function add(IndexKey $key) |
||
117 | |||
118 | /** |
||
119 | * Deletes key(s) from the index. |
||
120 | * |
||
121 | * @param IndexKey|int|string $key_or_id_or_uuid_or_hash |
||
122 | * |
||
123 | * @throws \InvalidArgumentException if `$key_or_id_or_uuid_or_hash` is not of the expected type. |
||
124 | */ |
||
125 | public function delete($key_or_id_or_uuid_or_hash) |
||
139 | |||
140 | /** |
||
141 | * Finds composite keys. |
||
142 | * |
||
143 | * @param IndexKey|int|string $key_or_id_or_uuid_or_hash |
||
144 | * |
||
145 | * @return IndexKey[] |
||
146 | * |
||
147 | * @throws \InvalidArgumentException if `$key_or_id_or_uuid_or_hash` is not of the expected type. |
||
148 | */ |
||
149 | public function find($key_or_id_or_uuid_or_hash) |
||
164 | |||
165 | /** |
||
166 | * Returns the composite key matching the composite key. |
||
167 | * |
||
168 | * @param IndexKey|string $key |
||
169 | * |
||
170 | * @return IndexKey[] |
||
171 | */ |
||
172 | protected function find_by_key($key) |
||
178 | |||
179 | /** |
||
180 | * Returns the composite keys match an identifier. |
||
181 | * |
||
182 | * @param int $id The node identifier to match. |
||
183 | * |
||
184 | * @return IndexKey[] |
||
185 | */ |
||
186 | protected function find_by_id($id) |
||
190 | |||
191 | /** |
||
192 | * Returns the composite keys match a v4 UUID. |
||
193 | * |
||
194 | * @param string $encoded_uuid The UUID to match. |
||
195 | * |
||
196 | * @return IndexKey[] |
||
197 | */ |
||
198 | protected function find_by_encoded_uuid($encoded_uuid) |
||
202 | |||
203 | /** |
||
204 | * Returns the composite keys match a v4 UUID. |
||
205 | * |
||
206 | * @param string $uuid The UUID to match. |
||
207 | * |
||
208 | * @return IndexKey[] |
||
209 | */ |
||
210 | protected function find_by_uuid($uuid) |
||
214 | |||
215 | /** |
||
216 | * Returns the composite keys match a hash. |
||
217 | * |
||
218 | * @param string $hash A hash from {@link Pathname::hash()} |
||
219 | * |
||
220 | * @return IndexKey[] |
||
221 | */ |
||
222 | protected function find_by_hash($hash) |
||
226 | |||
227 | /** |
||
228 | * Returns the composite keys matching a pattern. |
||
229 | * |
||
230 | * @param string $pattern The pattern to match. |
||
231 | * |
||
232 | * @return IndexKey[] |
||
233 | */ |
||
234 | protected function matching($pattern) |
||
248 | } |
||
249 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.