/** * @param LogicInterface $logic * @param array $parameters * * @return mixed * @throws \Exception */ public function handle(LogicInterface $logic, $parameters) { if (count($logic->getRules()) > 0) { foreach ($logic->getRules() as $rule) { $result = $this->language->evaluate($rule->getExpression(), $parameters); foreach ($rule->getActions() as $action) { if ($result == $action->getResult()) { switch ($action->getType()) { case ActionInterface::EXCEPTION: throw new \Exception($action->getParameter()); break; default: throw new \Exception("Unkown type"); break; } } } } } }
/** * @param \EasyRules\EngineBundle\Domain\Entity\Logic\Rule\Action $action * @param $parameters * * @return mixed * @throws \EasyRules\SimpleBusBridgeBundle\Exception\UnkownClassException */ private function createEvent(Action $action, $parameters) { $class = $action->getParameter(); if (!class_exists($class)) { throw new UnkownClassException("Class {$class} doesn\t exist"); } $event = new $class(); $parameters['event'] = $event; $this->language->evaluate($action->getEventExpression(), $parameters); return $event; }