Created
May 9, 2012 18:40
-
-
Save alejandrolechuga/2647859 to your computer and use it in GitHub Desktop.
SoapClass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set("soap.wsdl_cache_enabled", "0"); | |
ini_set("soap.wsdl_cache", "0"); | |
ini_set("display_errors","On"); | |
ini_set("track_errors","On"); | |
class Soap | |
{ | |
public $client; | |
public $login; | |
public $isSOAPAvailable = true; | |
public $response; | |
public $methodCall=''; | |
public $parameters = array(); | |
public $lastFailedURL = ""; | |
public $lastURL = ""; | |
function __contruct() | |
{ | |
} | |
function init($url,$params=array()) | |
{ | |
if ($this->lastURL == $url) { | |
return true; | |
} | |
if(DEFAULT_SOAP_ENABLED) { | |
/*if(!$params[DEFAULT_SOAP_login_key]) | |
$params[DEFAULT_SOAP_login_key] = DEFAULT_SOAP_login; | |
if(!$params[DEFAULT_SOAP_password_key]) | |
$params[DEFAULT_SOAP_password_key] = DEFAULT_SOAP_password;*/ | |
} | |
try | |
{ | |
$this->lastURL = $url; | |
$time = microtime(true); | |
$this->client = new SoapClient( | |
$url. '&r=' . rand(10,1000), | |
array( | |
'SOAP' => SOAP_1_2, | |
"style" => SOAP_DOCUMENT, | |
'trace' => 1, | |
'encoding'=>'ISO-8859-1' | |
//"uri" => "urn:xmethods-delayed-quotes" | |
// "uri"=>"env:myWS" | |
)); | |
$time = microtime(true) - $time; | |
}catch(Exception $e) | |
{ | |
echo $e; | |
echo "<br />"; | |
echo 'Error de Conexion'; | |
echo $url; | |
echo "<br />"; | |
echo "<br />"; | |
exit; | |
$this->isSOAPAvailable = false; | |
} | |
if($this->client)return true; | |
else return false; | |
} | |
function SOAPMethod($name, $parameters=array()) | |
{ | |
$return_variable = false; | |
try | |
{ | |
if($this->isSOAPAvailable) | |
{ | |
// echo "calling"; | |
$this->methodCall = $name; | |
$this->parameters = $parameters; | |
$time = microtime(true); | |
//echo 'Error se ejecuta [' . $name . ']'; | |
//if ($name == 'ActualizaCuentasBancoOp') | |
$return_variable = $this->client->__soapCall($name,$parameters); | |
// echo 'Error se ejecuta [' . $name . ']'; | |
$time = microtime(true) - $time; | |
$this->response = $return_variable; | |
$this->saveLog(); | |
/* | |
echo 'WEB SERVICE METHOD CALL TIME "'.$name.'"[' . $time .' µs]<br />'; | |
echo '<strong>Last Request Headers:</strong> <br />'; | |
echo $this->client->__getLastRequestHeaders(); | |
echo '<br />'; | |
echo '<br />'; | |
echo '<strong>Last Response Headers:</strong> <br />'; | |
echo $this->client->__getLastResponseHeaders(); | |
echo '<br />'; | |
echo '<br />'; | |
echo '<br />'; | |
echo '<strong>Last Response:</strong> <br />'; | |
echo '<pre>'; | |
echo htmlentities(formatXmlString($this->client->__getLastResponse())); | |
echo '</pre>'; | |
echo '<br />'; | |
echo '<br />'; | |
echo 'aqui'; | |
var_dump($return_variable); | |
echo 'aqui'; | |
echo '<br />'; | |
echo '<pre>'; | |
var_dump($this->client); | |
echo '</pre>'; | |
echo '<br />'; | |
echo '<strong>Last Response:</strong> <br />'; | |
echo htmlentities($this->client->__getLastResponse()); | |
echo '<br />'; | |
echo '<br />'; | |
echo '<strong>Last Request:</strong> <br />'; | |
echo '<pre>'; | |
echo htmlentities(formatXmlString($this->client->__getLastRequest())); | |
echo '</pre>'; | |
echo '<br />'; | |
echo '<br />'; | |
echo '<br />'; | |
echo '<strong>Error:</strong> <br />'. $fault; | |
echo '<br />'; | |
echo '<br />'; | |
echo '<strong>Types:</strong> <br />'; | |
echo '<pre>'; | |
echo print_r($this->client->__getTypes()); | |
echo '</pre>'; | |
echo '<br />'; | |
echo '<br />'; | |
echo '<strong>Functions:</strong> <br />'; | |
echo '<pre>'; | |
echo print_r($this->client->__getFunctions()); | |
echo '</pre>'; | |
*/ | |
} | |
else | |
{ | |
echo 'Web Service no disponible'; | |
} | |
}catch(SoapFault $fault) { | |
if (function_exists("errorHandler")) { | |
$error_string = "method : " + $name; | |
$error_string .= "\n"; | |
$error_string .= "Last Request: "; | |
$error_string .= "<code>" .$this->client->__getLastRequest() . "</code>"; | |
$error_string .= "Last Response: "; | |
$error_string .= "<code>" .$this->client->__getLastResponse() . "</code>"; | |
$error_string .= "Fault: "; | |
$error_string .= "<code>" .$fault . "</code>"; | |
//$error_number, $error_string, $error_file, $error_line, $error_context | |
errorHandler(666, $error_string, "SOAP FAULT -ERROR DE SERVICIOS-", __LINE__, $error_string); | |
} | |
$return_variable = array("failed" =>true); | |
} | |
return $return_variable; | |
} | |
function arrayToSOAPParameters($array) | |
{ | |
$array_of_soap_objects = array(); | |
foreach($array as $key => $value) | |
{ | |
$array_of_soap_objects[] = new SoapParam | |
( | |
$value, | |
$key | |
); | |
} | |
return $array_of_soap_objects; | |
} | |
function saveLog($error=false) | |
{ | |
if (!function_exists("formatXmlString")) { | |
return false; | |
} | |
$lastRequestHeaders = $this->client->__getLastRequestHeaders(); | |
$lastResponseHeaders = $this->client->__getLastResponseHeaders(); | |
$lastRequestBody = $this->client->__getLastRequest(); | |
$lastResponseBody = $this->client->__getLastResponse(); | |
$lastDataTypes = $this->client->__getTypes(); | |
$lastFunctions = $this->client->__getFunctions(); | |
$html = '<html>'; | |
$html .= ' <head></head>'; | |
$html .= ' <body>'; | |
$html .= ' <div><strong>DATE:</strong>' . @date('Y-m-d H:i:s') . '</div>'; | |
$html .= ' <div><strong>METHOD CALL:</strong>' . $this->methodCall . '</div>'; | |
$html .= ' <div><strong>ARRAY PARAMETERS:</strong><br /><textarea style="width:100%;height:50px;">' . print_r($this->parameters,true) . '</textarea></div>'; | |
$html .= ' <div><strong>LAST REQUEST HEADERS:</strong><br /><textarea style="width:100%;height:100px;">' . $lastRequestHeaders . '</textarea></div>'; | |
$html .= ' <div><strong>LAST RESPONSE HEADERS:</strong><br /><textarea style="width:100%;height:100px;">' . $lastResponseHeaders . '</textarea></div>'; | |
$html .= ' <div><strong>LAST REQUEST BODY:</strong><br /><textarea style="width:100%;height:100px;">' . htmlentities(formatXmlString($lastRequestBody)) . '</textarea></div>'; | |
$html .= ' <div><strong>LAST RESPONSE BODY:</strong><br /><textarea style="width:100%;height:100px;">' . htmlentities(formatXmlString($lastResponseBody)) . '</textarea></div>'; | |
$html .= ' <div><strong>LAST DATA TYPES:</strong><br/><textarea style="width:100%;height:100px;">' . $lastDataTypes . '</textarea></div>'; | |
$html .= ' <div><strong>LAST FUNCIONS:</strong><br /><textarea style="width:100%;height:100px;">' . $lastFunctions . '</textarea></div>'; | |
$html .= ' <div><strong>ARRAY RESPONSE:</strong><br /><textarea style="width:100%;height:100px;">' . print_r($this->response,true) . '</textarea></div>'; | |
if($error) | |
{ | |
$html .= ' <div><strong>ERROR:</strong><br /><textarea style="width:50%;height:100px;">' . $error . '</textarea></div>'; | |
} | |
$html .= ' </body>'; | |
$html .= '</html>'; | |
$fh = @fopen( LOGS_SOAP . $this->methodCall . '.html', "wa+"); | |
if($fh) | |
{ | |
fputs( $fh, $html, strlen($html) ); | |
fclose( $fh ); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment