예제 #1
0
 protected function validateJobParams(Job $job)
 {
     if (empty($job->getSender())) {
         throw new ResultException(ResultException::ERROR_PARAM_SENDER);
     }
     if (empty($job->getRecipient())) {
         throw new ResultException(ResultException::ERROR_PARAM_RECIPIENT);
     }
     if (empty($job->getText())) {
         throw new ResultException(ResultException::ERROR_PARAM_TEXT);
     }
 }
예제 #2
0
 /**
  * @param Job $job
  *
  * @return array
  * @throws WorkerException
  */
 protected function analiseGateway(Job $job)
 {
     $gatewayClassSet = self::getConfig(self::GATEWAY_CLASS_SET);
     if (count($gatewayClassSet) === 0) {
         throw new WorkerException('Empty gateway class set!');
     }
     $gatewayClassScore = [];
     foreach ($gatewayClassSet as $gatewayClass => $gatewayOptions) {
         $gatewayClassScore[$gatewayClass] = 0;
         if (preg_match($gatewayOptions[self::GATEWAY_CLASS_P_REGEX_RECIPIENT], $job->getRecipient())) {
             $gatewayClassScore[$gatewayClass]++;
         }
         // ......
     }
     $maxClass = array_keys($gatewayClassScore, max($gatewayClassScore))[0];
     if ($gatewayClassScore[$maxClass] === 0) {
         // Transport is bad : $maxClass = 0 , and we have no ideas what return :(
     }
     return $maxClass;
 }