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