| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDeveloper\BetterDocs\Admin\Builder; |
| 4 |
|
| 5 |
use JsonSerializable; |
| 6 |
|
| 7 |
class Rule implements JsonSerializable { |
| 8 |
public $condition; |
| 9 |
public $name; |
| 10 |
public $value; |
| 11 |
public function __construct( $condition, $name, $value ) { |
| 12 |
$this->condition = $condition; |
| 13 |
$this->name = $name; |
| 14 |
$this->value = $value; |
| 15 |
} |
| 16 |
|
| 17 |
public function add_value( $value ) { |
| 18 |
if ( ! is_array( $this->value ) ) { |
| 19 |
$this->value = [ $this->value ]; |
| 20 |
} |
| 21 |
if ( is_a( $value, 'NotificationX\Core\Rule' ) ) { |
| 22 |
$value = $value->value; |
| 23 |
} |
| 24 |
if ( is_array( $value ) ) { |
| 25 |
$this->value = array_merge( $this->value, $value ); |
| 26 |
} else { |
| 27 |
$this->value[] = $value; |
| 28 |
} |
| 29 |
$this->value = array_values( array_unique( $this->value ) ); |
| 30 |
} |
| 31 |
|
| 32 |
public function can_add( $rule ) { |
| 33 |
if ( $this->condition == 'includes' && $this->condition == $rule->condition && $this->name == $rule->name ) { |
| 34 |
return true; |
| 35 |
} |
| 36 |
return false; |
| 37 |
} |
| 38 |
|
| 39 |
#[\ReturnTypeWillChange] |
| 40 |
public function jsonSerialize() { |
| 41 |
return [ |
| 42 |
$this->condition, |
| 43 |
$this->name, |
| 44 |
$this->value |
| 45 |
]; |
| 46 |
} |
| 47 |
} |
| 48 |
|