| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Give\Vendors\StellarWP\FieldConditions; |
| 6 |
|
| 7 |
use ArrayIterator; |
| 8 |
use Give\Vendors\StellarWP\FieldConditions\Concerns\HasConditions; |
| 9 |
use Give\Vendors\StellarWP\FieldConditions\Contracts\Condition; |
| 10 |
use Give\Vendors\StellarWP\FieldConditions\Contracts\ConditionSet; |
| 11 |
|
| 12 |
/** |
| 13 |
* @implements ConditionSet<Condition> |
| 14 |
* @uses HasConditions<Condition> |
| 15 |
*/ |
| 16 |
class ComplexConditionSet implements ConditionSet |
| 17 |
{ |
| 18 |
use HasConditions; |
| 19 |
|
| 20 |
/** |
| 21 |
* @since 1.0.0 |
| 22 |
* |
| 23 |
* @param Condition ...$conditions |
| 24 |
*/ |
| 25 |
public function __construct(...$conditions) |
| 26 |
{ |
| 27 |
$this->validateConditions($conditions); |
| 28 |
$this->conditions = $conditions; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* @inheritDoc |
| 33 |
* |
| 34 |
* @since 1.0.0 |
| 35 |
*/ |
| 36 |
public function getIterator(): ArrayIterator |
| 37 |
{ |
| 38 |
return new ArrayIterator($this->conditions); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* @inheritDoc |
| 43 |
* |
| 44 |
* @since 1.0.0 |
| 45 |
*/ |
| 46 |
public function jsonSerialize(): array |
| 47 |
{ |
| 48 |
return array_map( |
| 49 |
static function (Condition $condition) { |
| 50 |
return $condition->jsonSerialize(); |
| 51 |
}, |
| 52 |
$this->conditions |
| 53 |
); |
| 54 |
} |
| 55 |
} |
| 56 |
|