/**
  * @param ContextInterface $context
  * @param RuleInterface    $rule
  * @param ActionInterface  $action
  * @param string|null      $message
  * @param \Exception|null  $previous
  */
 public function __construct($context, $rule, $action, $message = null, $previous = null)
 {
     $this->action = $action;
     if ($message === null) {
         $message = sprintf('%s encountered while executing action %s for rule %s (%s) within %s%s', is_object($previous) ? get_class($previous) : 'Error', get_class($this->getAction()), $rule->getId(), $rule->getName(), get_class($context), is_object($previous) ? ': ' . $previous->getMessage() : '');
     }
     parent::__construct($context, $rule, $message, $previous);
 }
Esempio n. 2
0
 /**
  * @param RuleInterface[] $result
  * @param RuleInterface   $rule
  */
 protected function findMatchesForContextRule(&$result, $rule)
 {
     $cond = $rule->getCondition();
     $match = $cond === '' ? true : $this->evaluator->evaluate($rule->getCondition());
     if (!is_bool($match)) {
         throw new \RuntimeException(sprintf('The condition result for rule %s (%s) should be boolean, not %s.', $rule->getId(), $rule->getName(), gettype($match)));
     }
     if ($match) {
         $result[] = $rule;
     }
 }
Esempio n. 3
0
 /**
  * @param EvaluatorInterface $eval
  * @param ContextInterface   $context
  * @param RuleInterface      $rule
  */
 public function execute($eval, $context, $rule)
 {
     printf('Rule %s (%s) triggered for %s.' . PHP_EOL, $rule->getId(), $rule->getName(), (string) $context);
 }