Collection.php
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\FieldsAPI\Contracts; |
| 4 | |
| 5 | use Give\Framework\FieldsAPI\Field; |
| 6 | |
| 7 | interface Collection |
| 8 | { |
| 9 | /** |
| 10 | * @since 2.10.2 |
| 11 | * |
| 12 | * Fluently append nodes to the collection. |
| 13 | * |
| 14 | * @return $this do not add return type until PHP 7.4 is minimum |
| 15 | */ |
| 16 | public function append(Node ...$nodes); |
| 17 | |
| 18 | /** |
| 19 | * Fluently remove a named node. |
| 20 | * |
| 21 | * @since 2.10.2 |
| 22 | * |
| 23 | * @return mixed |
| 24 | */ |
| 25 | public function remove(string $name); |
| 26 | |
| 27 | /** |
| 28 | * Get all the nodes. |
| 29 | * |
| 30 | * @since 2.10.2 |
| 31 | * |
| 32 | * @return Node[] |
| 33 | */ |
| 34 | public function all(): array; |
| 35 | |
| 36 | /** |
| 37 | * Count all the nodes. |
| 38 | * |
| 39 | * @since 2.10.2 |
| 40 | * |
| 41 | * @return int |
| 42 | */ |
| 43 | public function count(): int; |
| 44 | |
| 45 | /** |
| 46 | * Get a node’s index by its name. |
| 47 | * |
| 48 | * @since 2.10.2 |
| 49 | * |
| 50 | * @return int|null |
| 51 | */ |
| 52 | public function getNodeIndexByName(string $name); |
| 53 | |
| 54 | /** |
| 55 | * Get a node by its name. |
| 56 | * |
| 57 | * @since 2.10.2 |
| 58 | * |
| 59 | * @return Node|Collection |
| 60 | */ |
| 61 | public function getNodeByName(string $name); |
| 62 | |
| 63 | /** |
| 64 | * Get only the field nodes. |
| 65 | * |
| 66 | * @return Field[] |
| 67 | */ |
| 68 | public function getFields(): array; |
| 69 | |
| 70 | /** |
| 71 | * Inserts the given noe after the node with the given name. |
| 72 | * |
| 73 | * @since 2.10.2 |
| 74 | * |
| 75 | * @return $this |
| 76 | */ |
| 77 | public function insertAfter(string $siblingName, Node $node); |
| 78 | |
| 79 | /** |
| 80 | * Inserts the given noe before the node with the given name. |
| 81 | * |
| 82 | * @since 2.10.2 |
| 83 | * |
| 84 | * @return $this |
| 85 | */ |
| 86 | public function insertBefore(string $siblingName, Node $node); |
| 87 | |
| 88 | /** |
| 89 | * Walk through each node in the collection |
| 90 | * |
| 91 | * @since 2.10.2 |
| 92 | * |
| 93 | * @return void |
| 94 | */ |
| 95 | public function walk(callable $callback); |
| 96 | } |
| 97 |