PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.9
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.9
1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 All 211 releases
charitable / includes / libraries / wp-session / class-recursive-arrayaccess.php

class-recursive-arrayaccess.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.7.0.9, at includes/libraries/wp-session/class-recursive-arrayaccess.php

222 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Multidimensional ArrayAccess
4 *
5 * Allows ArrayAccess-like functionality with multidimensional arrays. Fully supports
6 * both sets and unsets.
7 *
8 * @package WordPress
9 * @subpackage Session
10 * @since 3.7.0
11 */
12
13 /**
14 * Recursive array class to allow multidimensional array access.
15 *
16 * @package WordPress
17 * @since 3.7.0
18 */
19 class Recursive_ArrayAccess implements ArrayAccess, Iterator, Countable {
20 /**
21 * Internal data collection.
22 *
23 * @var array
24 */
25 protected $container = array();
26
27 /**
28 * Flag whether or not the internal collection has been changed.
29 *
30 * @var bool
31 */
32 protected $dirty = false;
33
34 /**
35 * Default object constructor.
36 *
37 * @param array $data
38 */
39 protected function __construct( $data = array() ) {
40 foreach ( $data as $key => $value ) {
41 $this[ $key ] = $value;
42 }
43 }
44
45 /**
46 * Allow deep copies of objects
47 */
48 public function __clone() {
49 foreach ( $this->container as $key => $value ) {
50 if ( $value instanceof self ) {
51 $this[ $key ] = clone $value;
52 }
53 }
54 }
55
56 /**
57 * Output the data container as a multidimensional array.
58 *
59 * @return array
60 */
61 public function toArray() {
62 $data = $this->container;
63 foreach ( $data as $key => $value ) {
64 if ( $value instanceof self ) {
65 $data[ $key ] = $value->toArray();
66 }
67 }
68 return $data;
69 }
70
71 /*****************************************************************/
72 /* ArrayAccess Implementation */
73 /*****************************************************************/
74
75 /**
76 * Whether a offset exists
77 *
78 * @link http://php.net/manual/en/arrayaccess.offsetexists.php
79 *
80 * @param mixed $offset An offset to check for.
81 *
82 * @return boolean true on success or false on failure.
83 */
84 #[\ReturnTypeWillChange]
85 public function offsetExists( $offset ) {
86 return isset( $this->container[ $offset ]) ;
87 }
88
89 /**
90 * Offset to retrieve
91 *
92 * @link http://php.net/manual/en/arrayaccess.offsetget.php
93 *
94 * @param mixed $offset The offset to retrieve.
95 *
96 * @return mixed Can return all value types.
97 */
98 #[\ReturnTypeWillChange]
99 public function offsetGet( $offset ) {
100 return isset( $this->container[ $offset ] ) ? $this->container[ $offset ] : null;
101 }
102
103 /**
104 * Offset to set
105 *
106 * @link http://php.net/manual/en/arrayaccess.offsetset.php
107 *
108 * @param mixed $offset The offset to assign the value to.
109 * @param mixed $value The value to set.
110 *
111 * @return void
112 */
113 public function offsetSet( $offset, $data ) : void {
114 if ( is_array( $data ) ) {
115 $data = new self( $data );
116 }
117 if ( $offset === null ) { // don't forget this!
118 $this->container[] = $data;
119 } else {
120 $this->container[ $offset ] = $data;
121 }
122
123 $this->dirty = true;
124 }
125
126 /**
127 * Offset to unset
128 *
129 * @link http://php.net/manual/en/arrayaccess.offsetunset.php
130 *
131 * @param mixed $offset The offset to unset.
132 *
133 * @return void
134 */
135 public function offsetUnset( $offset ) : void {
136 unset( $this->container[ $offset ] );
137
138 $this->dirty = true;
139 }
140
141
142 /*****************************************************************/
143 /* Iterator Implementation */
144 /*****************************************************************/
145
146 /**
147 * Current position of the array.
148 *
149 * @link http://php.net/manual/en/iterator.current.php
150 *
151 * @return mixed
152 */
153 #[\ReturnTypeWillChange]
154 public function current() {
155 return current( $this->container );
156 }
157
158 /**
159 * Key of the current element.
160 *
161 * @link http://php.net/manual/en/iterator.key.php
162 *
163 * @return mixed
164 */
165 #[\ReturnTypeWillChange]
166 public function key() {
167 return key( $this->container );
168 }
169
170 /**
171 * Move the internal point of the container array to the next item
172 *
173 * @link http://php.net/manual/en/iterator.next.php
174 *
175 * @return void
176 */
177 #[\ReturnTypeWillChange]
178 public function next() {
179 next( $this->container );
180 }
181
182 /**
183 * Rewind the internal point of the container array.
184 *
185 * @link http://php.net/manual/en/iterator.rewind.php
186 *
187 * @return void
188 */
189 #[\ReturnTypeWillChange]
190 public function rewind() {
191 reset( $this->container );
192 }
193
194 /**
195 * Is the current key valid?
196 *
197 * @link http://php.net/manual/en/iterator.rewind.php
198 *
199 * @return bool
200 */
201 #[\ReturnTypeWillChange]
202 public function valid() {
203 return $this->offsetExists( $this->key() );
204 }
205
206 /*****************************************************************/
207 /* Countable Implementation */
208 /*****************************************************************/
209
210 /**
211 * Get the count of elements in the container array.
212 *
213 * @link http://php.net/manual/en/countable.count.php
214 *
215 * @return int
216 */
217 #[\ReturnTypeWillChange]
218 public function count() {
219 return count( $this->container );
220 }
221 }
222