| 1 |
<?php |
| 2 |
namespace Depicter\Rules\DisplayCondition; |
| 3 |
|
| 4 |
class DisplayConditionGroup { |
| 5 |
|
| 6 |
/** |
| 7 |
* @var string |
| 8 |
*/ |
| 9 |
public $matchingMode = 'all'; |
| 10 |
|
| 11 |
/** |
| 12 |
* @var int |
| 13 |
*/ |
| 14 |
public $order = 0; |
| 15 |
|
| 16 |
/** |
| 17 |
* @var string |
| 18 |
*/ |
| 19 |
public $operator = 'or'; |
| 20 |
|
| 21 |
/** |
| 22 |
* Condition instances in this group |
| 23 |
* |
| 24 |
* @var \Depicter\Rules\Condition\Base[] |
| 25 |
*/ |
| 26 |
public $conditions; |
| 27 |
|
| 28 |
/** |
| 29 |
* Condition instances in this group |
| 30 |
* |
| 31 |
* @return \Depicter\Rules\Condition\Base[] |
| 32 |
*/ |
| 33 |
public function conditions(){ |
| 34 |
return $this->conditions; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Check if conditions are passed in current matchingMode |
| 39 |
* |
| 40 |
* @param $value |
| 41 |
* |
| 42 |
* @return bool |
| 43 |
*/ |
| 44 |
public function check( $value = null ){ |
| 45 |
|
| 46 |
if( ! empty( $this->conditions ) ){ |
| 47 |
|
| 48 |
if( $this->matchingMode === 'any' ){ |
| 49 |
foreach( $this->conditions as $condition ){ |
| 50 |
if( $condition->check( $value ) ){ |
| 51 |
return true; |
| 52 |
} |
| 53 |
} |
| 54 |
return false; |
| 55 |
|
| 56 |
// if matchingMode is set to 'all' |
| 57 |
} else { |
| 58 |
foreach( $this->conditions as $condition ){ |
| 59 |
if( ! $condition->check( $value ) ){ |
| 60 |
return false; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
return true; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
return true; |
| 69 |
} |
| 70 |
} |
| 71 |
|