/**
  * @param \Dafiti\Correios\Entity\RequestObject $request
  *
  * @return bool
  */
 public function validate(Entity\RequestObject $request)
 {
     $errors = false;
     foreach ($this->validationRules as $validationRule) {
         list($fields, $rule, $options) = $validationRule;
         foreach ($fields as $field) {
             $class = '\\Dafiti\\Correios\\Validator\\' . $rule;
             $reflection = new \ReflectionClass($class);
             $validator = $reflection->newInstance($options);
             $data = $request->getArrayCopy();
             $fieldList = explode('.', $field);
             $result = $validator->validate($this->getValue($data, $fieldList));
             if ($result !== true) {
                 $errors = true;
                 $this->errors[$field][] = $result;
             }
         }
     }
     return !$errors;
 }
示例#2
0
 public function call($method, Entity\RequestObject $obj)
 {
     try {
         $response = $this->{$method}($obj->getArrayCopy());
     } catch (\SoapFault $fault) {
         throw new \SoapFault("SOAP Fault: (faultcode: {$fault->faultcode}," . " faultstring: {$fault->faultstring})", E_USER_ERROR);
     } finally {
         // log request and response
         if (!empty($this->config->getLogPath())) {
             try {
                 $path = $this->config->getLogPath();
                 $path .= time() . "_{$method}_";
                 $this->getLogFile($path . 'REQ.xml')->fwrite($this->__getLastRequest());
                 $this->getLogFile($path . 'RES.xml')->fwrite($this->__getLastResponse());
             } catch (\RuntimeException $e) {
                 throw new \RuntimeException('Unable to write log files.');
             }
         }
     }
     return new Entity\ResponseObject($response);
 }