Source for file jSoapClient.class.php

Documentation is available at jSoapClient.class.php

  1. <?php
  2. /**
  3. @package     jelix
  4. @subpackage  utils
  5. @author      Laurent Jouanneau
  6. @copyright   2011 Laurent Jouanneau
  7. @link        http://jelix.org
  8. @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  9. */
  10.  
  11.  
  12. /**
  13.  * class that handles a dump of a php value, for a logger
  14.  */
  15. class  jLogSoapMessage extends jLogMessage {
  16.     /**
  17.      * @var string 
  18.      */
  19.     protected $headers;
  20.     /**
  21.      * @var string 
  22.      */
  23.     protected $request;
  24.     /**
  25.      * @var string 
  26.      */
  27.     protected $response;
  28.     /**
  29.      * @var string 
  30.      */
  31.     protected $duration;
  32.  
  33.     public function __construct($function_name$soapClient$category='default'$duration 0{
  34.         $this->category = $category;
  35.         $this->headers = $soapClient->__getLastRequestHeaders();
  36.         $this->request = $soapClient->__getLastRequest ();
  37.         $this->response = $soapClient->__getLastResponse();
  38.         $this->functionName $function_name;
  39.         $this->duration = $duration;
  40.         $this->message = 'Soap call: '.$function_name.'()';
  41.     }
  42.  
  43.     public function getHeaders({
  44.         return $this->headers;
  45.     }
  46.  
  47.     public function getResponse({
  48.         return $this->response;
  49.     }
  50.  
  51.     public function getRequest({
  52.         return $this->request;
  53.     }
  54.  
  55.     public function getDuration({
  56.         return $this->duration;
  57.     }
  58.  
  59.     public function getFormatedMessage({
  60.         $message =  'Soap call: '.$this->functionName."()\n";
  61.         $message .= "DURATION: ".$this->duration."s\n";
  62.         $message .= "HEADERS:\n\t".str_replace("\n","\n\t",$this->headers)."\n";
  63.         $message .= "REQUEST:\n\t".str_replace("\n","\n\t",$this->request)."\n";
  64.         $message .= "RESPONSE:\n\t".str_replace("\n","\n\t",$this->response)."\n";
  65.         return $message;
  66.     }
  67. }
  68.  
  69.  
  70.  
  71. class SoapClientDebug extends SoapClient {
  72.     public function __call $function_name $arguments{
  73.         $timeExecutionBegin $this->_microtimeFloat();
  74.         $ex false;
  75.         try {
  76.             $result parent::__call($function_name $arguments);
  77.         }
  78.         catch(Exception $e{
  79.             $ex $e;
  80.         }
  81.         $timeExecutionEnd $this->_microtimeFloat();
  82.  
  83.         $log new jLogSoapMessage($function_name$this'soap'$timeExecutionEnd $timeExecutionBegin);
  84.         jLog::log($log,'soap');
  85.         if ($ex)
  86.             throw $ex;
  87.         return $result;
  88.     }
  89.  
  90.     public function __soapCall $function_name $arguments$options=array()$input_headers=null,  &$output_headers=null{
  91.         $timeExecutionBegin $this->_microtimeFloat();
  92.         $ex false;
  93.         try {
  94.             $result parent::__soapCall($function_name $arguments$options$input_headers,  $output_headers);
  95.         }
  96.         catch(Exception $e{
  97.             $ex $e;
  98.         }
  99.         $timeExecutionEnd $this->_microtimeFloat();
  100.         $log new jLogSoapMessage($function_name$this'soap'$timeExecutionEnd $timeExecutionBegin);
  101.         jLog::log($log,'soap');
  102.         if ($ex)
  103.             throw $ex;
  104.         return $result;
  105.     }
  106.  
  107.     protected function _microtimeFloat({
  108.         list($usec$secexplode(" "microtime());
  109.         return ((float)$usec + (float)$sec);
  110.     }
  111. }
  112.  
  113.  
  114.  
  115. /**
  116. * provide a soap client where configuration information are stored in the profile file
  117. @package     jelix
  118. @subpackage  utils
  119. */
  120. class jSoapClient {
  121.  
  122.     /**
  123.      * @param string $profile  the profile name
  124.      */
  125.     public static function get($profile ''{
  126.         return jProfiles::getOrStoreInPool('jsoapclient'$profilearray('jSoapClient''_getClient'));
  127.     }
  128.  
  129.     /**
  130.      * callback method for jprofiles. Internal use.
  131.      */
  132.     public static function _getClient($profile{
  133.         $wsdl null;
  134.         $client 'SoapClient';
  135.         if (isset($profile['wsdl'])) {
  136.             $wsdl $profile['wsdl'];
  137.             if ($wsdl == '')
  138.                 $wsdl null;
  139.             unset ($profile['wsdl']);
  140.         }
  141.         if (isset($profile['trace'])) {
  142.             $profile['trace'intval($profile['trace'])// SoapClient recognize only true integer
  143.             if ($profile['trace'])
  144.                 $client 'SoapClientDebug';
  145.         }
  146.         if (isset($profile['exceptions'])) {
  147.             $profile['exceptions'intval($profile['exceptions'])// SoapClient recognize only true integer
  148.         }
  149.         if (isset($profile['connection_timeout'])) {
  150.             $profile['connection_timeout'intval($profile['connection_timeout'])// SoapClient recognize only true integer
  151.         }
  152.         unset ($profile['_name']);
  153.         if (isset($profile['classmap']&& is_string ($profile['classmap']&& $profile['classmap'!= ''{
  154.             $profile['classmap'= (array)json_decode(str_replace("'"'"',$profile['classmap']));
  155.         }
  156.  
  157.         //$context = stream_context_create( array('http' => array('max_redirects' => 3)));
  158.         //$profile['stream_context'] = $context;
  159.  
  160.         return new $client($wsdl$profile);
  161.     }
  162. }

Documentation generated on Mon, 26 Oct 2015 21:56:24 +0100 by phpDocumentor 1.4.3