| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\Aws\EndpointV2\Rule; |
| 4 |
|
| 5 |
use Dudlewebs\WPMCS\s3\Aws\EndpointV2\Ruleset\RulesetStandardLibrary; |
| 6 |
/** |
| 7 |
* A rule within a rule set. All rules contain a conditions property, |
| 8 |
* which can be empty, and documentation about the rule. |
| 9 |
*/ |
| 10 |
abstract class AbstractRule |
| 11 |
{ |
| 12 |
private $conditions; |
| 13 |
private $documentation; |
| 14 |
public function __construct(array $definition) |
| 15 |
{ |
| 16 |
$this->conditions = $definition['conditions']; |
| 17 |
$this->documentation = isset($definition['documentation']) ? $definition['documentation'] : null; |
| 18 |
} |
| 19 |
/** |
| 20 |
* @return array |
| 21 |
*/ |
| 22 |
public function getConditions() |
| 23 |
{ |
| 24 |
return $this->conditions; |
| 25 |
} |
| 26 |
/** |
| 27 |
* @return mixed |
| 28 |
*/ |
| 29 |
public function getDocumentation() |
| 30 |
{ |
| 31 |
return $this->documentation; |
| 32 |
} |
| 33 |
/** |
| 34 |
* Determines if all conditions for a given rule are met. |
| 35 |
* |
| 36 |
* @return boolean |
| 37 |
*/ |
| 38 |
protected function evaluateConditions(array &$inputParameters, RulesetStandardLibrary $standardLibrary) |
| 39 |
{ |
| 40 |
foreach ($this->getConditions() as $condition) { |
| 41 |
$result = $standardLibrary->callFunction($condition, $inputParameters); |
| 42 |
if (\is_null($result) || $result === \false) { |
| 43 |
return \false; |
| 44 |
} |
| 45 |
} |
| 46 |
return \true; |
| 47 |
} |
| 48 |
public abstract function evaluate(array $inputParameters, RulesetStandardLibrary $standardLibrary); |
| 49 |
} |
| 50 |
|