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.     public function __construct($function_name, $soapClient, $category='default') {
  30.         $this->category = $category;
  31.         $this->headers = $soapClient->__getLastRequestHeaders();
  32.         $this->request = $soapClient->__getLastRequest ();
  33.         $this->response = $soapClient->__getLastResponse();
  34.         $this->functionName = $function_name;
  35.         $this->message = 'Soap call: '.$function_name.'()';
  36.     }
  37.  
  38.     public function getHeaders() {
  39.         return $this->headers;
  40.     }
  41.  
  42.     public function getResponse() {
  43.         return $this->response;
  44.     }
  45.  
  46.     public function getRequest() {
  47.         return $this->request;
  48.     }
  49.  
  50.     public function getFormatedMessage() {
  51.         $message =  'Soap call: '.$this->functionName."()\n";
  52.         $message .= "HEADERS:\n\t".str_replace("\n","\n\t",$this->headers)."\n";
  53.         $message .= "REQUEST:\n\t".str_replace("\n","\n\t",$this->request)."\n";
  54.         $message .= "RESPONSE:\n\t".str_replace("\n","\n\t",$this->response)."\n";
  55.         return $message;
  56.     }
  57. }
  58.  
  59.  
  60.  
  61. class SoapClientDebug extends SoapClient {
  62.     public function __call ( $function_name , $arguments) {
  63.         $result = parent::__call($function_name , $arguments);
  64.         $log = new jLogSoapMessage($function_name, $this, 'soap');
  65.         jLog::log($log,'soap');
  66.         return $result;
  67.     }
  68.  
  69.     public function __soapCall ( $function_name , $arguments, $options=array(), $input_headers=null,  &$output_headers=null) {
  70.         $result = parent::__soapCall($function_name , $arguments, $options, $input_headers,  $output_headers);
  71.         $log = new jLogSoapMessage($function_name, $this, 'soap');
  72.         jLog::log($log,'soap');
  73.         return $result;
  74.     }
  75. }
  76.  
  77.  
  78.  
  79. /**
  80. * provide a soap client where configuration information are stored in the profile file
  81. * @package     jelix
  82. * @subpackage  utils
  83. */
  84. class jSoapClient {
  85.  
  86.     /**
  87.      * @param string $profile  the profile name
  88.      */
  89.     public static function get($profile = '') {
  90.         return jProfiles::getOrStoreInPool('jsoapclient', $profile, array('jSoapClient', '_getClient'));
  91.     }
  92.  
  93.     /**
  94.      * callback method for jprofiles. Internal use.
  95.      */
  96.     public static function _getClient($profile) {
  97.         $wsdl = null;
  98.         $client = 'SoapClient';
  99.         if (isset($profile['wsdl'])) {
  100.             $wsdl = $profile['wsdl'];
  101.             if ($wsdl == '')
  102.                 $wsdl = null;
  103.             unset ($profile['wsdl']);
  104.         }
  105.         if (isset($profile['trace'])) {
  106.             $profile['trace'] = intval($profile['trace']); // SoapClient recognize only true integer
  107.             if ($profile['trace'])
  108.                 $client = 'SoapClientDebug';
  109.         }
  110.         if (isset($profile['exceptions'])) {
  111.             $profile['exceptions'] = intval($profile['exceptions']); // SoapClient recognize only true integer
  112.         }
  113.         if (isset($profile['connection_timeout'])) {
  114.             $profile['connection_timeout'] = intval($profile['connection_timeout']); // SoapClient recognize only true integer
  115.         }
  116.         unset ($profile['_name']);
  117.         if (isset($profile['classmap']) && is_string ($profile['classmap']) && $profile['classmap'] != '') {
  118.             $profile['classmap'] = (array)json_decode(str_replace("'", '"',$profile['classmap']));
  119.         }
  120.         return new $client($wsdl, $profile);
  121.     }
  122. }

Documentation generated on Mon, 19 Sep 2011 14:13:39 +0200 by phpDocumentor 1.4.3