示例#1
0
 /**
  * Initializes the class
  *
  * @param SimpleXMLIterator $result
  * @throws IntacctException
  */
 public function __construct(SimpleXMLIterator $result)
 {
     if (!isset($result->status)) {
         throw new IntacctException('Result block is missing status element');
     }
     if (!isset($result->function)) {
         throw new IntacctException('Result block is missing function element');
     }
     if (!isset($result->controlid)) {
         throw new IntacctException('Result block is missing controlid element');
     }
     $this->status = strval($result->status);
     $this->function = strval($result->function);
     $this->controlId = strval($result->controlid);
     $status = $this->getStatus();
     if ($status !== 'success') {
         $errors = [];
         if (isset($result->errormessage)) {
             $errorMessage = new ErrorMessage($result->errormessage);
             $errors = $errorMessage->getErrors();
         }
         $this->errors = $errors;
     }
     if (isset($result->data)) {
         $this->data = $result->data;
         if (isset($result->data->attributes()->listtype)) {
             $this->listtype = strval($result->data->attributes()->listtype);
         }
         if (isset($result->data->attributes()->count)) {
             $this->count = intval($result->data->attributes()->count);
         }
         if (isset($result->data->attributes()->totalcount)) {
             $this->totalcount = intval($result->data->attributes()->totalcount);
         }
         if (isset($result->data->attributes()->numremaining)) {
             $this->numremaining = intval($result->data->attributes()->numremaining);
         }
         if (isset($result->data->attributes()->resultId)) {
             $this->resultId = strval($result->data->attributes()->resultId);
         }
     }
 }
示例#2
0
 /**
  * Initializes the class
  *
  * @param SimpleXMLIterator $operation
  */
 public function __construct(SimpleXMLIterator $operation)
 {
     if (!isset($operation->authentication)) {
         throw new IntacctException('Authentication block is missing from operation element');
     }
     $this->setAuthentication($operation->authentication);
     if ($this->authentication->getStatus() !== 'success') {
         $errors = [];
         if (isset($operation->errormessage)) {
             $errorMessage = new ErrorMessage($operation->errormessage);
             $errors = $errorMessage->getErrors();
         }
         throw new OperationException('Response authentication status failure', $errors);
     }
     if (!isset($operation->result[0])) {
         throw new IntacctException('Result block is missing from operation element');
     }
     foreach ($operation->result as $result) {
         $this->setResult($result);
     }
 }
 /**
  * Initializes the class with the given body XML response
  *
  * @param string $body
  * @throws IntacctException
  * @throws ResponseException
  */
 public function __construct($body)
 {
     libxml_use_internal_errors(true);
     $this->xml = simplexml_load_string($body, 'SimpleXMLIterator');
     if ($this->xml === false) {
         throw new IntacctException('XML could not be parsed properly');
     }
     libxml_clear_errors();
     libxml_use_internal_errors(false);
     if (!isset($this->xml->control)) {
         throw new IntacctException('Response is missing control block');
     }
     $this->setControl($this->xml->control);
     if ($this->control->getStatus() !== 'success') {
         $errors = [];
         if (isset($this->xml->errormessage)) {
             $errorMessage = new ErrorMessage($this->xml->errormessage);
             $errors = $errorMessage->getErrors();
         }
         throw new ResponseException('Response control status failure', $errors);
     }
 }