| 1 |
<?php |
| 2 |
namespace Elementor\Core\Utils; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; // Exit if accessed directly. |
| 6 |
} |
| 7 |
|
| 8 |
class Static_Collection { |
| 9 |
|
| 10 |
/** |
| 11 |
* The current Collection instance. |
| 12 |
* |
| 13 |
* @var Collection |
| 14 |
*/ |
| 15 |
protected $collection; |
| 16 |
|
| 17 |
/** |
| 18 |
* Return only unique values. |
| 19 |
* |
| 20 |
* @var bool |
| 21 |
*/ |
| 22 |
protected $unique_values = false; |
| 23 |
|
| 24 |
/** |
| 25 |
* @inheritDoc |
| 26 |
*/ |
| 27 |
public function __construct( array $items = [], $unique_values = false ) { |
| 28 |
$this->collection = new Collection( $items ); |
| 29 |
$this->unique_values = $unique_values; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Since this class is a wrapper, every call will be forwarded to wrapped class. |
| 34 |
* Most of the collection methods returns a new collection instance, and therefore |
| 35 |
* it will be assigned as the current collection instance after executing any method. |
| 36 |
* |
| 37 |
* @param string $name |
| 38 |
* @param array $arguments |
| 39 |
*/ |
| 40 |
public function __call( $name, $arguments ) { |
| 41 |
$call = call_user_func_array( [ $this->collection, $name ], $arguments ); |
| 42 |
|
| 43 |
if ( $call instanceof Collection ) { |
| 44 |
$this->collection = $this->unique_values ? |
| 45 |
$call->unique() : |
| 46 |
$call; |
| 47 |
} |
| 48 |
|
| 49 |
return $call; |
| 50 |
} |
| 51 |
} |
| 52 |
|