/** * Constructor * * @param unknown $message * @param unknown $code * @param unknown $previous */ public function __construct(ApiResponse $response, $previous = null) { $this->message = $response->getErrorMessage(); $this->code = $response->getHttpResponse()->getstatusCode(); $this->apiErrorCode = $response->getApiErrorCode(); }
/** * Magical function to use API method has API Manager method. * * @param string $action * @param array $args * @return ApiResponse; */ public function __call($action, $args) { $methodConf = 'get'; $apiConfig = $this->getApiConfig(); $actionOptions = $apiConfig[$action]['options']; if (isset($actionOptions['defaults']['apiMethod'])) { $methodConf = $actionOptions['defaults']['apiMethod']; } $apiRequest = new Request($this->getTargetServer(), $action, $this->getApiKey()); if (isset($args[0])) { if ($methodConf == 'post') { $files = array(); if (isset($actionOptions['files'])) { foreach ($actionOptions['files'] as $fileParam) { if (isset($args[0][$fileParam])) { $filePath = $args[0][$fileParam]; if (!is_file($filePath)) { throw new \Exception('File not readable or non existent: ' . $filePath); } $files[$filePath] = array('formname' => $fileParam, 'filename' => basename($filePath), 'data' => null, 'ctype' => null); unset($args[0][$fileParam]); } } unset($args[0]['files']); } if (count($files)) { $apiRequest->setFiles(new \Zend\Stdlib\Parameters($files)); } } $apiRequest->setParameters($args[0]); } $outputFormat = $this->outputFormat; if (isset($args[0]['zsoutput'])) { $outputFormat = $args[0]['zsoutput']; } $apiRequest->setOutputType($outputFormat); if ($methodConf == 'post') { $apiRequest->setMethod(Request::METHOD_POST); } $apiRequest->prepareRequest(); $log = $this->getServiceLocator()->get('log'); $log->info($apiRequest->getUriString()); $httpResponse = $this->getZendServerClient()->send($apiRequest); $response = ApiResponse::factory($httpResponse); if ($response->isError()) { $error = ''; if (!getenv('RAW_ZS_OUTPUT')) { $error .= $response->getErrorMessage(); } else { $writers = new \Zend\StdLib\SplPriorityQueue(); foreach ($log->getWriters() as $writer) { $writer->setFormatter(new \Zend\Log\Formatter\Simple('%message%')); $writers->insert($writer, 1); } $log->setWriters($writers); } $error .= $response->getHttpResponse()->getBody(); $log->err($error); throw new ApiException($response); } return $response; }