/** * @param Rule $rule * @param WorkingMemory $workingMemory * * @return array */ public function execute(Rule $rule, WorkingMemory $workingMemory) { $facts = $workingMemory->getAllFacts(); /** * @param string $_action * @return array */ $executor = function ($_action) use($facts) { extract($facts); unset($facts); eval($_action); unset($_action); return get_defined_vars(); }; $workingMemory->setAllFacts($executor($rule->getAction())); $workingMemory->setExecuted($rule->getRule()); }
/** * @param Rule $rule */ public function addIterationRuleExecution(Rule $rule) { $this->currentIterationExecution = sizeof($this->inferences[$this->currentInference]['iterations'][$this->currentIteration]['executions']); $this->inferences[$this->currentInference]['iterations'][$this->currentIteration]['executions'][$this->currentIterationExecution] = ['name' => $rule->getName(), 'action' => $rule->getAction()]; }
/** * @param Rule $rule * @param WorkingMemory $workingMemory * * @return array */ private function execAction(Rule $rule, WorkingMemory $workingMemory) { $facts = $workingMemory->getAllFacts(); /** * @param string $_action * @return array */ $executor = function ($_action) use($facts) { extract($facts); unset($facts); eval($_action); unset($_action); return get_defined_vars(); }; $code = trim($rule->getAction()); $code = $code . (preg_match('/;$/i', $code) ? '' : ';'); return $executor($code); }
/** * @return string */ public function getAction() { return $this->rule->getAction(); }