Log by mail

This commit is contained in:
Michael RICOIS 2015-07-15 07:18:25 +00:00
parent 188a0c6941
commit e2d7be2280

View File

@ -53,6 +53,10 @@ class Scores_Ws_Client extends Zend_Soap_Client
*/
protected $url = null;
/**
* Objet de cache
* @var object
*/
protected $cache;
/**
@ -66,7 +70,7 @@ class Scores_Ws_Client extends Zend_Soap_Client
*/
public function __construct($name, $version, $user = null)
{
//Configuration de l'application
// --- Configuration de l'application
if (Zend_Registry::isRegistered('config')) {
$c = Zend_Registry::get('config');
$this->url = $c->profil->webservice->url;
@ -75,7 +79,7 @@ class Scores_Ws_Client extends Zend_Soap_Client
$this->url = $c->profil->webservice->url;
}
//Configuration du service
// --- Configuration du service
$config = include __DIR__ . '/Client/' . ucfirst($name) . '.php';
if ($config === false) {
throw new Exception('Impossible de charger la configuration du service');
@ -87,7 +91,7 @@ class Scores_Ws_Client extends Zend_Soap_Client
$this->config = $config[$version];
// Create WSDL url
// --- Create WSDL url
$wsdl = $this->url . '/' . $name . '/v' . $version;
if (APPLICATION_ENV == 'development') {
$wsdl.= '?wsdl-auto';
@ -107,7 +111,7 @@ class Scores_Ws_Client extends Zend_Soap_Client
$this->setHttpPassword($user->getPassword());
}
//Add default options
// --- Add default options
$options = array(
'features' => SOAP_USE_XSI_ARRAY_TYPE + SOAP_SINGLE_ELEMENT_ARRAYS,
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE,
@ -116,9 +120,9 @@ class Scores_Ws_Client extends Zend_Soap_Client
);
$this->setOptions($options);
// Create Cache
// --- Create Cache
$frontend = array(
'lifetime' => 28800,
'lifetime' => 14400,
'automatic_seralization' => true
);
$backend = array(
@ -139,7 +143,7 @@ class Scores_Ws_Client extends Zend_Soap_Client
$methodConfig = $this->config[$name];
//Cache
// --- Cache
$cacheEnable = false;
if ( array_key_exists('cache', $methodConfig) ) {
if ( $methodConfig['cache'] === true ) {
@ -153,7 +157,7 @@ class Scores_Ws_Client extends Zend_Soap_Client
}
}
//Cache
// --- Cache
if ( $cacheEnable === true ) {
$response = $this->cache->load($cacheId);
if ( $response !== false ) {
@ -161,7 +165,7 @@ class Scores_Ws_Client extends Zend_Soap_Client
}
}
//Debug
// --- Debug
if ( array_key_exists('debug', $methodConfig) ) {
Zend_Registry::get('firebug')->info(__CLASS__.'->'.$name);
Zend_Registry::get('firebug')->info($arguments);
@ -171,12 +175,12 @@ class Scores_Ws_Client extends Zend_Soap_Client
$response = parent::__call($name, $arguments);
//Debug
// --- Debug
if ( array_key_exists('debug', $methodConfig) ) {
Zend_Registry::get('firebug')->info($response);
}
//Cache
// --- Cache
if ( $cacheEnable === true ) {
$this->cache->save($response->{$name.'Result'}, $cacheId);
}
@ -185,21 +189,46 @@ class Scores_Ws_Client extends Zend_Soap_Client
} catch ( SoapFault $fault ) {
//Debug
// --- Debug
if ( array_key_exists('debug', $methodConfig) ) {
Zend_Registry::get('firebug')->info($fault->faultcode.' - '.$fault->faultstring);
}
//Gestion des SOAP fault
// --- Gestion des SOAP fault
if ( array_key_exists('errorMsg', $methodConfig) ) {
if ( in_array($fault->faultcode, $methodConfig['errorMsg']) ) {
throw new Exception($fault->faultstring);
}
}
//Logging
if ( array_key_exists('log', $methodConfig) ) {
// --- Logging
if ( array_key_exists('log', $methodConfig) ) {
// --- Envoi email de contexte
if( $methodConfig['log'] == 'mail' ) {
$message = '';
$message.= 'Erreur SOAP - Code : '.$fault->faultcode.' - Message : '.$fault->faultstring;
$message.= ' - Utilisateur : '.$this->getHttpLogin();
$message.= "\n\n";
$message.= "Method : ".$name.", File :".$fault->getFile().", Ligne : ".$fault->getLine();
$message.= "\n\n";
$message.= "Detail :\n".$fault->getTraceAsString();
$message.= "\n\n";
if ( $controller = Zend_Controller_Front::getInstance() ) {
$message.= "Request Parameters :\n ".print_r($controller->getRequest()->getParams(), true);
$message.= "\n\n";
}
$message.= "Referer : ".$_SERVER['HTTP_REFERER']."\n\n";
$message.= "Requete :\n ".$requete."\n";
$message.= "Reponse :\n ".$reponse."\n";
$c = Zend_Registry::get('config');
$mail = new Scores_Mail_Method();
$mail->setSubject('[ERREUR SOAP] - '.$c->profil->server->name.' -'.date('Ymd'));
$mail->setBodyTextC($message);
$mail->setFromKey('supportdev');
$mail->addToKey('supportdev');
$mail->execute();
}
}
return false;
@ -208,7 +237,7 @@ class Scores_Ws_Client extends Zend_Soap_Client
/**
*
* @param unknown $url
* @param string $url
*/
protected function setUrl($url)
{