PluginProbe
Elementor Website Builder – more than just a page builder / 3.20.2
Elementor Website Builder – more than just a page builder v3.20.2
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 -67 4.2.0-dev23.20.2 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
@@ -343,23 +331,8 @@
343 331 return false;
344 332 }
345 333
346 334 /**
347 - * Run array_diff between the collection and other array or collection.
348 - *
349 - * @param $filter
350 - *
351 - * @return $this
352 - */
353 - public function diff( $filter ) {
354 - if ( $filter instanceof self ) {
355 - $filter = $filter->all();
356 - }
357 -
358 - return new static( array_diff( $this->all(), $filter ) );
359 - }
360 -
361 - /**
362 335 * Make sure all the values inside the array are uniques.
363 336 *
364 337 * @param null|string|string[] $keys
365 338 *
@@ -402,10 +375,13 @@
402 375 return false;
403 376 } );
404 377 }
405 378
379 + /**
380 + * @return array
381 + */
406 382 public function keys() {
407 - return new static( array_keys( $this->items ) );
383 + return array_keys( $this->items );
408 384 }
409 385
410 386 /**
411 387 * @return bool
@@ -452,14 +428,10 @@
452 428
453 429 return new static( $result );
454 430 }
455 431
456 - public function flip() {
457 - return new static( array_flip( $this->items ) );
458 - }
459 -
460 432 /**
461 - * @param array ...$values
433 + * @param ...$values
462 434 *
463 435 * @return $this
464 436 */
465 437 public function push( ...$values ) {
@@ -475,28 +447,8 @@
475 447
476 448 return $this;
477 449 }
478 450
479 - public function some( callable $callback ) {
480 - foreach ( $this->items as $key => $item ) {
481 - if ( $callback( $item, $key ) ) {
482 - return true;
483 - }
484 - }
485 -
486 - return false;
487 - }
488 -
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 451 /**
500 452 * @param mixed $offset
501 453 *
502 454 * @return bool
@@ -555,14 +507,14 @@
555 507
556 508 /**
557 509 * @param $item
558 510 * @param $key
559 - * @param null $fallback
511 + * @param null $default
560 512 *
561 513 * @return mixed|null
562 514 */
563 - private function get_item_value( $item, $key, $fallback = null ) {
564 - $value = $fallback;
515 + private function get_item_value( $item, $key, $default = null ) {
516 + $value = $default;
565 517
566 518 if ( is_object( $item ) && isset( $item->{$key} ) ) {
567 519 $value = $item->{$key};
568 520 } elseif ( is_array( $item ) && isset( $item[ $key ] ) ) {