Exemplo n.º 1
0
 /**
  * @author WN
  * @param DataSources $dataSources
  * @param Rule $rule
  * @return Value
  * @throws ProcessingException
  */
 private function fetchValue(DataSources $dataSources, Rule $rule)
 {
     $source = $dataSources->getDataSource($rule->getSource());
     if (!method_exists($source, $rule->getField())) {
         throw new ProcessingException('Field [' . $rule->getField() . '] not exists in source [' . $rule->getSource() . ']');
     }
     $value = $source->{$rule->getField()}();
     if (!$value instanceof Value) {
         throw new ProcessingException('Field [' . $rule->getField() . '] in source [' . $rule->getSource() . '] must be Value type');
     }
     return $value;
 }
Exemplo n.º 2
0
 /**
  * @author WN
  * @param Rule $rule
  * @param Value $value
  * @param float $noMatchRisk
  * @return RuleAdvice
  */
 public function process(Rule $rule, Value $value, $noMatchRisk = Risk::MAXIMUM_RISK)
 {
     $advice = RuleAdvice::make(['rule' => $rule, 'value' => $value, 'risk' => $noMatchRisk]);
     foreach ($rule->getConditions() as $condition) {
         try {
             if ($condition->checkCondition($value)) {
                 $advice->setRisk($condition->getRisk());
                 $advice->setCondition($condition);
                 break;
             }
         } catch (ProcessingException $e) {
             $advice->addExceptions('Processing condition [' . $condition->getValue() . ']: ' . $e->getMessage());
         }
     }
     $advice->setMeta(['processor' => 'First match standard rule processor', 'no_match_risk' => $noMatchRisk]);
     return $advice;
 }