Initial Commit

This commit is contained in:
GiacomoHome
2021-09-17 12:41:45 +02:00
commit 9001e4656e
570 changed files with 31013 additions and 0 deletions
+84
View File
@@ -0,0 +1,84 @@
<?php
class App_Model_CurlHttpClient
{
protected $_httpClient = null;
protected $_urlNameServices;
public function __construct($urlName){
$this->_urlNameServices = $urlName;
$this->_httpClient = new Zend_Http_Client($urlName);
$this->_httpClient->setConfig(array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'maxredirects' => 0,
'timeout' => 60,
'ssltransport' => 'ssl'
));
}
/***** METODI COMUNI DELLE CHIMATE *****/
public function getCall($params){
$this->_httpClient->setMethod('GET');
$this->_httpClient->setParameterGet($params);
return $this->executeCall();
}
public function postCall($dati,$formatJson = false){
$this->_httpClient->setMethod('POST');
if($formatJson)
$this->_httpClient->setRawData(json_encode($dati),'application/json;charset=utf-8');
else
$this->_httpClient->setParameterPost($dati);
return $this->executeCall();
}
public function putCall($dati,$formatJson = false){
$this->_httpClient->setMethod('PUT');
if($formatJson)
$this->_httpClient->setRawData(json_encode($dati),'application/json;charset=utf-8');
else
$this->_httpClient->setParameterPost($dati);
return $this->executeCall();
}
public function deleteCall($params){
$this->_httpClient->setMethod('DELETE');
$this->_httpClient->setParameterGet($params);
return $this->executeCall();
}
/***** METODI PRIVATI PER GESTIRE LE CHIAMATE *****/
private function executeCall(){
$httpResponse = $this->_httpClient->request();
$headerResponse = $httpResponse->getHeaders();
if(preg_match('/application\/json/',$headerResponse['Content-type'])){
$httpResponseBody = json_decode($httpResponse->getBody(),1);
if(json_last_error() !== JSON_ERROR_NONE){
Zend_Registry::get('log')->info($this->_httpClient->getUri());
Zend_Registry::get('log')->info("Errore codifica JSON:");
Zend_Registry::get('log')->info(print_r($httpResponse,true));
return null;
}
if (!$httpResponseBody['status'] && !$httpResponseBody['success']) {
Zend_Registry::get('log')->info($this->_httpClient->getUri());
Zend_Registry::get('log')->info("Errore 'httpResponse' no status or success code:");
Zend_Registry::get('log')->info(print_r($httpResponseBody,true));
throw new Exception($httpResponseBody['message'],$httpResponseBody['errorCode']);
}
}else{
$httpResponseBody = $httpResponse->getBody();
}
return $httpResponseBody;
}
}