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.     protected static $classmap array();
  123.  
  124.     /**
  125.      * @param string $profile  the profile name
  126.      */
  127.     public static function get($profile ''{
  128.         return jProfiles::getOrStoreInPool('jsoapclient'$profilearray('jSoapClient''_getClient'));
  129.     }
  130.  
  131.     /**
  132.      * callback method for jprofiles. Internal use.
  133.      */
  134.     public static function _getClient($profile{
  135.         $wsdl null;
  136.         $client 'SoapClient';
  137.         if (isset($profile['wsdl'])) {
  138.             $wsdl $profile['wsdl'];
  139.             if ($wsdl == '')
  140.                 $wsdl null;
  141.             unset ($profile['wsdl']);
  142.         }
  143.         if (isset($profile['trace'])) {
  144.             $profile['trace'intval($profile['trace'])// SoapClient recognize only true integer
  145.             if ($profile['trace'])
  146.                 $client 'SoapClientDebug';
  147.         }
  148.         if (isset($profile['exceptions'])) {
  149.             $profile['exceptions'intval($profile['exceptions'])// SoapClient recognize only true integer
  150.         }
  151.         if (isset($profile['connection_timeout'])) {
  152.             $profile['connection_timeout'intval($profile['connection_timeout'])// SoapClient recognize only true integer
  153.         }
  154.  
  155.         // deal with classmap
  156.         $classMap array();
  157.         if (isset($profile['classmap_file']&& ($f trim($profile['classmap_file'])) != ''{
  158.             if (!isset(self::$classmap[$f])) {
  159.                 if (!file_exists(jApp::configPath($f))) {
  160.                     trigger_error("jSoapClient: classmap file ".$f." does not exists."E_USER_WARNING);
  161.                     self::$classmap[$farray();
  162.                 }
  163.                 else {
  164.                     self::$classmap[$fparse_ini_file(jApp::configPath($f)true);
  165.                 }
  166.             }
  167.             if (isset(self::$classmap[$f]['__common__'])) {
  168.                 $classMap array_merge($classMapself::$classmap[$f]['__common__']);
  169.             }
  170.             if (isset(self::$classmap[$f][$profile['_name']])) {
  171.                 $classMap array_merge($classMapself::$classmap[$f][$profile['_name']]);
  172.             }
  173.             unset($profile['classmap_file']);
  174.         }
  175.  
  176.         if (isset($profile['classmap']&& is_string ($profile['classmap']&& $profile['classmap'!= ''{
  177.             $map = (array)json_decode(str_replace("'"'"',$profile['classmap']));
  178.             $classMap array_merge($classMap$map);
  179.             unset($profile['classmap']);
  180.         }
  181.  
  182.         if (count($classMap)) {
  183.             $profile['classmap'$classMap;
  184.         }
  185.  
  186.         //$context = stream_context_create( array('http' => array('max_redirects' => 3)));
  187.         //$profile['stream_context'] = $context;
  188.         unset ($profile['_name']);
  189.  
  190.         return new $client($wsdl$profile);
  191.     }
  192. }

Documentation generated on Wed, 04 Jan 2017 22:56:59 +0100 by phpDocumentor 1.4.3