Beispiel #1
0
 function _ResponseResultToResponseArray($SomeResult)
 {
     $this->responsearray = array();
     if (empty($SomeResult)) {
         // $SomeArray
         // we have an error
         $this->responsearray['status'] = 'Error';
         $this->responsearray['statusCode'] = '500';
         $this->responsearray['errorDescription'] = 'No Response';
         return;
     }
     //echo '<br>$this->ContentType='.$this->ContentType.'<br>';
     if ($this->ContentType != 'JSON' && $this->ContentType != 'PHPSERIAL' && $this->ContentType != 'XML') {
         $this->ContentType = 'JSON';
     }
     //echo '<br>$this->ContentType='.$this->ContentType.'<br>';
     if ($this->ContentType == 'JSON') {
         if (class_exists('Services_JSON')) {
             //$JSONObj = new Services_JSON();
             //return $JSONObj->encode($SomeArray);
             $JSONObj = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
             $this->responsearray = $JSONObj->decode($SomeResult);
         } else {
             // throw error
             trigger_error("ERROR: Services_JSON class not available", E_USER_ERROR);
         }
     } else {
         if ($this->ContentType == 'XML') {
             if (class_exists('XMLParser')) {
                 $parser = new XMLParser($SomeResult, false, false);
                 $parser->Parse();
                 $this->responsearray = $parser->ReturnArray();
                 $this->responsearray = $this->responsearray['root'];
                 // this forces the 'results' response to always have a child 0, xml can omit this
                 if (isset($this->responsearray['results']) && is_array($this->responsearray['results']) && !isset($this->responsearray['results']['0']) && count($this->responsearray['results'] > 0)) {
                     $temparray = $this->responsearray['results'];
                     unset($this->responsearray['results']);
                     $this->responsearray['results']['0'] = $temparray;
                     unset($temparray);
                 }
                 //$XMLObj = new ArrayXML( $SomeArray );
                 //return  '<'.'?'.'xml version="1.0" encoding="UTF-8" ?'.'>'."\n".'<root>'."\n".$XMLObj->ReturnXML().'</root>';
             } else {
                 // throw error
                 trigger_error("ERROR: XMLParser class not available", E_USER_ERROR);
             }
         } else {
             if ($this->ContentType == 'PHPSERIAL') {
                 //return serialize($SomeArray);
                 $this->responsearray = unserialize($SomeResult);
                 //if ( is_array( $this->xmlarray ) )
                 //{
                 //	$this->xmlarray['root'] = array_changekeycase_r( $this->xmlarray['root'], CASE_LOWER );
                 //}
             }
         }
     }
     if (!empty($this->responsearray['status'])) {
         $this->Status = $this->responsearray['status'];
     }
     if (!empty($this->responsearray['statusCode'])) {
         $this->StatusCode = $this->responsearray['statusCode'];
     }
     if (!empty($this->responsearray['errorDescription'])) {
         $this->ErrorDescription = $this->responsearray['errorDescription'];
     }
     // $this->responsearray['status'] = 'Success'
     // $this->responsearray['statusCode'] = '200'
     //}
     // default
     //$JSONObj = new Services_JSON();
     //return $JSONObj->encode($SomeArray);
 }