/** * Process results from any of the read methods and convert into the appropriate structure * * @param String $response result from post to Intacct Web Services * @param Integer &$count by reference count of records returned * @param string $returnFormat valid returnFormat value * * @throws Exception * @return Mixed string or object depending on return format */ private static function processReadResults($response, &$count, $returnFormat = api_returnFormat::PHPOBJ) { $objAry = array(); $csv = ''; $json = ''; $xml = ''; if ($returnFormat == api_returnFormat::PHPOBJ) { $objAry = api_util::csvToPhp($response); $count = count($objAry); return $objAry; } elseif ($returnFormat == api_returnFormat::JSON) { // this seems really expensive $objAry = json_decode($response); // todo: JSON doesn't work because we don't know what object to refer to throw new Exception("The JSON return format is not implemented yet."); } elseif ($returnFormat == api_returnFormat::XML) { $xmlObj = simplexml_load_string($response); foreach ($xmlObj->operation->result->data->attributes() as $attribute => $value) { if ($attribute == 'count') { $count = $value; break; } } $xml = $xmlObj->operation->result->data->view->asXml(); return $xml; } elseif ($returnFormat == api_returnFormat::CSV) { $objAry = api_util::csvToPhp($response); $count = count($objAry); $csv = $response; return $csv; } else { throw new Exception("Unknown return format {$returnFormat}. Refer to the api_returnFormat class."); } }