/** * @param Rule $rule * @param WorkingMemory $workingMemory * * @return bool */ public function checkCondition(Rule $rule, WorkingMemory $workingMemory) { try { return (bool) $this->expressionLanguage->evaluate($rule->getCondition(), $workingMemory->getAllFacts()); } catch (SyntaxError $e) { return false; } }
/** * @param Rule $rule * @param WorkingMemory $workingMemory * * @return bool */ private function execCondition(Rule $rule, WorkingMemory $workingMemory) { $facts = $workingMemory->getAllFacts(); /** * @param string $_action * @return array */ $executor = function ($_action) use($facts) { extract($facts); unset($facts); $_return = eval($_action); return $_return; }; $code = trim($rule->getCondition()); $code = (preg_match('/^return /i', $code) ? '' : 'return ') . $code; $code = $code . (preg_match('/;$/i', $code) ? '' : ';'); return $executor($code); }
/** * @param Rule $combinationRule */ public function addMatchingRuleCheckConditionWildcardCombinationCheck(Rule $combinationRule) { $this->currentMatchingRuleCheckConditionWildcard = sizeof($this->inferences[$this->currentInference]['iterations'][$this->currentIteration]['matchingRuleChecks'][$this->currentMatchingRuleCheck]['wildcard']); $this->inferences[$this->currentInference]['iterations'][$this->currentIteration]['matchingRuleChecks'][$this->currentMatchingRuleCheck]['wildcard'][$this->currentMatchingRuleCheckConditionWildcard] = ['name' => $combinationRule->getName(), 'condition' => $combinationRule->getCondition(), 'result' => '']; }
/** * @return string */ public function getCondition() { return $this->rule->getCondition(); }