| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Vendors\StellarWP\FieldConditions; |
| 4 |
|
| 5 |
use ArrayIterator; |
| 6 |
use Give\Vendors\StellarWP\FieldConditions\Concerns\HasConditions; |
| 7 |
use Give\Vendors\StellarWP\FieldConditions\Concerns\HasLogicalOperator; |
| 8 |
use Give\Vendors\StellarWP\FieldConditions\Contracts\Condition; |
| 9 |
use Give\Vendors\StellarWP\FieldConditions\Contracts\ConditionSet; |
| 10 |
|
| 11 |
/** |
| 12 |
* A condition that holds and evaluates multiple conditions. |
| 13 |
* |
| 14 |
* @since 1.1.1 implement the ConditionSet interface |
| 15 |
* @since 1.0.0 |
| 16 |
* |
| 17 |
* @uses HasConditions<Condition> |
| 18 |
*/ |
| 19 |
class NestedCondition implements Condition, ConditionSet |
| 20 |
{ |
| 21 |
use HasLogicalOperator; |
| 22 |
use HasConditions; |
| 23 |
|
| 24 |
/** |
| 25 |
* The type of condition. |
| 26 |
*/ |
| 27 |
const TYPE = 'nested'; |
| 28 |
|
| 29 |
/** |
| 30 |
* @since 1.0.0 |
| 31 |
* |
| 32 |
* @param Condition[] $conditions |
| 33 |
* @param 'and'|'or' $logicalOperator |
| 34 |
*/ |
| 35 |
public function __construct(array $conditions = [], string $logicalOperator = 'and') |
| 36 |
{ |
| 37 |
$this->conditions = $conditions; |
| 38 |
$this->setLogicalOperator($logicalOperator); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* @inheritDoc |
| 43 |
* |
| 44 |
* @since 1.0.0 |
| 45 |
*/ |
| 46 |
public function jsonSerialize(): array |
| 47 |
{ |
| 48 |
return [ |
| 49 |
'type' => static::TYPE, |
| 50 |
'conditions' => $this->conditions, |
| 51 |
'boolean' => $this->logicalOperator, |
| 52 |
]; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* @since 1.1.1 |
| 57 |
*/ |
| 58 |
public function getIterator(): ArrayIterator |
| 59 |
{ |
| 60 |
return new ArrayIterator($this->conditions); |
| 61 |
} |
| 62 |
} |
| 63 |
|