PluginProbe
Elementor Website Builder – more than just a page builder / 3.27.4
Elementor Website Builder – more than just a page builder v3.27.4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
← All changes | core/utils/collection.php +19 -42 4.2.13.27.4 View file →
@@ -1,12 +1,9 @@
1 1 <?php
2 2 /**
3 3 * Inspired by Laravel Collection.
4 - *
5 4 * @link https://github.com/illuminate/collections
6 - * @package Elementor\Core\Utils
7 5 */
8 -
9 6 namespace Elementor\Core\Utils;
10 7
11 8 if ( ! defined( 'ABSPATH' ) ) {
12 9 exit; // Exit if accessed directly.
@@ -11,13 +8,8 @@
11 8 if ( ! defined( 'ABSPATH' ) ) {
12 9 exit; // Exit if accessed directly.
13 10 }
14 11
15 -/**
16 - * Inspired by Laravel Collection.
17 - *
18 - * @link https://github.com/illuminate/collections
19 - */
20 12 class Collection implements \ArrayAccess, \Countable, \IteratorAggregate {
21 13 /**
22 14 * The items contained in the collection.
23 15 *
@@ -47,9 +39,9 @@
47 39 * @param callable|null $callback
48 40 *
49 41 * @return $this
50 42 */
51 - public function filter( ?callable $callback = null ) {
43 + public function filter( callable $callback = null ) {
52 44 if ( ! $callback ) {
53 45 return new static( array_filter( $this->items ) );
54 46 }
55 47
@@ -123,9 +115,9 @@
123 115
124 116 /**
125 117 * Run a map over each of the items.
126 118 *
127 - * @param callable $callback
119 + * @param callable $callback
128 120 * @return $this
129 121 */
130 122 public function map( callable $callback ) {
131 123 $keys = array_keys( $this->items );
@@ -166,12 +158,8 @@
166 158
167 159 return $result;
168 160 }
169 161
170 - public function reverse() {
171 - return new static( array_reverse( $this->items ) );
172 - }
173 -
174 162 /**
175 163 * @param callable $callback
176 164 *
177 165 * @return $this
@@ -274,15 +262,15 @@
274 262 /**
275 263 * Get specific item from the collection.
276 264 *
277 265 * @param $key
278 - * @param null $fallback
266 + * @param null $default
279 267 *
280 268 * @return mixed|null
281 269 */
282 - public function get( $key, $fallback = null ) {
270 + public function get( $key, $default = null ) {
283 271 if ( ! array_key_exists( $key, $this->items ) ) {
284 - return $fallback;
272 + return $default;
285 273 }
286 274
287 275 return $this->items[ $key ];
288 276 }
@@ -289,15 +277,15 @@
289 277
290 278 /**
291 279 * Get the first item.
292 280 *
293 - * @param null $fallback
281 + * @param null $default
294 282 *
295 283 * @return mixed|null
296 284 */
297 - public function first( $fallback = null ) {
285 + public function first( $default = null ) {
298 286 if ( $this->is_empty() ) {
299 - return $fallback;
287 + return $default;
300 288 }
301 289
302 290 foreach ( $this->items as $item ) {
303 291 return $item;
@@ -307,13 +295,13 @@
307 295 /**
308 296 * Find an element from the items.
309 297 *
310 298 * @param callable $callback
311 - * @param null $fallback
299 + * @param null $default
312 300 *
313 301 * @return mixed|null
314 302 */
315 - public function find( callable $callback, $fallback = null ) {
303 + public function find( callable $callback, $default = null ) {
316 304 foreach ( $this->all() as $key => $item ) {
317 305 if ( $callback( $item, $key ) ) {
318 306 return $item;
319 307 }
@@ -318,9 +306,9 @@
318 306 return $item;
319 307 }
320 308 }
321 309
322 - return $fallback;
310 + return $default;
323 311 }
324 312
325 313 /**
326 314 * @param callable|string|int $value
@@ -402,10 +390,13 @@
402 390 return false;
403 391 } );
404 392 }
405 393
394 + /**
395 + * @return array
396 + */
406 397 public function keys() {
407 - return new static( array_keys( $this->items ) );
398 + return array_keys( $this->items );
408 399 }
409 400
410 401 /**
411 402 * @return bool
@@ -452,14 +443,10 @@
452 443
453 444 return new static( $result );
454 445 }
455 446
456 - public function flip() {
457 - return new static( array_flip( $this->items ) );
458 - }
459 -
460 447 /**
461 - * @param array ...$values
448 + * @param ...$values
462 449 *
463 450 * @return $this
464 451 */
465 452 public function push( ...$values ) {
@@ -485,18 +472,8 @@
485 472
486 473 return false;
487 474 }
488 475
489 - public function every( callable $callback ) {
490 - foreach ( $this->items as $key => $item ) {
491 - if ( ! $callback( $item, $key ) ) {
492 - return false;
493 - }
494 - }
495 -
496 - return true;
497 - }
498 -
499 476 /**
500 477 * @param mixed $offset
501 478 *
502 479 * @return bool
@@ -555,14 +532,14 @@
555 532
556 533 /**
557 534 * @param $item
558 535 * @param $key
559 - * @param null $fallback
536 + * @param null $default
560 537 *
561 538 * @return mixed|null
562 539 */
563 - private function get_item_value( $item, $key, $fallback = null ) {
564 - $value = $fallback;
540 + private function get_item_value( $item, $key, $default = null ) {
541 + $value = $default;
565 542
566 543 if ( is_object( $item ) && isset( $item->{$key} ) ) {
567 544 $value = $item->{$key};
568 545 } elseif ( is_array( $item ) && isset( $item[ $key ] ) ) {