PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.1.0
JetFormBuilder — Dynamic Blocks Form Builder v2.1.0
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / classes / arrayable / collection.php
jetformbuilder / includes / classes / arrayable Last commit date
array-continue-exception.php 3 years ago array-convert-once.php 3 years ago array-tools.php 3 years ago arrayable-once.php 3 years ago arrayable.php 3 years ago collection-item-interface.php 3 years ago collection.php 3 years ago
collection.php
165 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Classes\Arrayable;
5
6
7 class Collection implements \Iterator, \Countable, \ArrayAccess {
8
9 private $position = 0;
10 private $items;
11
12 public function __construct( array $items = array() ) {
13 $this->items = $items;
14 }
15
16 public function intersect( $list_of_states ): bool {
17 foreach ( $list_of_states as $state ) {
18 if ( $this->in_array( $state ) ) {
19 return true;
20 }
21 }
22
23 return false;
24 }
25
26 /**
27 * @param $state
28 *
29 * @return bool
30 */
31 public function in_array( $state ): bool {
32 if ( is_object( $state ) ) {
33 $state = get_class( $state );
34 }
35
36 if ( class_exists( $state ) ) {
37 return $this->in_array_by_class( $state );
38 }
39
40 return $this->in_array_by_id( $state );
41 }
42
43 protected function in_array_by_class( $state_class ): bool {
44 foreach ( $this as $state ) {
45 if ( is_a( $state, $state_class ) ) {
46 return true;
47 }
48 }
49
50 return false;
51 }
52
53 protected function in_array_by_id( $state_class ): bool {
54 /** @var Collection_Item_Interface $state */
55 foreach ( $this as $state ) {
56 if ( ! ( $state instanceof Collection_Item_Interface ) ) {
57 continue;
58 }
59 if ( $state->get_id() !== $state_class ) {
60 return true;
61 }
62 }
63
64 return false;
65 }
66
67 public function add( $item ): Collection {
68 $this->items[] = $item;
69
70 return $this;
71 }
72
73 public function delete( $position ): Collection {
74 unset( $this->items[ $position ] );
75
76 return $this;
77 }
78
79 /*
80 * \Iterator
81 */
82
83 /**
84 * @return mixed
85 */
86 public function current() {
87 return $this->items[ $this->position ];
88 }
89
90
91 public function next() {
92 ++ $this->position;
93 }
94
95 /**
96 * @return bool|float|int|string|null
97 */
98 public function key() {
99 return $this->position;
100 }
101
102 /**
103 * @return bool
104 */
105 public function valid() {
106 return isset( $this->items[ $this->position ] );
107 }
108
109 public function rewind() {
110 $this->position = 0;
111 }
112
113 /*
114 * \ArrayAccess
115 */
116
117 /**
118 * @param mixed $offset
119 *
120 * @return bool
121 */
122 public function offsetExists( $offset ) {
123 return isset( $this->items[ $offset ] );
124 }
125
126 /**
127 * @param mixed $offset
128 *
129 * @return mixed
130 */
131 public function offsetGet( $offset ) {
132 return $this->items[ $offset ] ?? null;
133 }
134
135 /**
136 * @param mixed $offset
137 * @param mixed $value
138 */
139 public function offsetSet( $offset, $value ) {
140 if ( is_null( $offset ) ) {
141 $this->items[] = $value;
142 } else {
143 $this->items[ $offset ] = $value;
144 }
145 }
146
147 /**
148 * @param mixed $offset
149 */
150 public function offsetUnset( $offset ) {
151 unset( $this->items[ $offset ] );
152 }
153
154 /*
155 * \Countable
156 */
157
158 /**
159 * @return int
160 */
161 public function count() {
162 return count( $this->items );
163 }
164
165 }