Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/zend/Zend/Soap/Client.php
Go to the documentation of this file.
00001 <?php
00026 require_once 'Zend/Soap/Server.php';
00027 
00031 require_once 'Zend/Soap/Client/Local.php';
00032 
00036 require_once 'Zend/Soap/Client/Common.php';
00037 
00047 class Zend_Soap_Client
00048 {
00053     protected $_encoding = 'UTF-8';
00054 
00059     protected $_classmap = null;
00060 
00065     protected $_faultExceptions = array();
00066 
00071     protected $_soapVersion = SOAP_1_2;
00072 
00074     protected $_uri                 = null;
00075     protected $_location            = null;
00076     protected $_style               = null;
00077     protected $_use                 = null;
00078     protected $_login               = null;
00079     protected $_password            = null;
00080     protected $_proxy_host          = null;
00081     protected $_proxy_port          = null;
00082     protected $_proxy_login         = null;
00083     protected $_proxy_password      = null;
00084     protected $_local_cert          = null;
00085     protected $_passphrase          = null;
00086     protected $_compression         = null;
00087     protected $_connection_timeout  = null;
00088     protected $_stream_context      = null;
00089     protected $_features            = null;
00090     protected $_cache_wsdl          = null;
00091     protected $_user_agent          = null;
00092 
00099     protected $_wsdl = null;
00100 
00106     protected $_soapClient;
00107 
00113     protected $_lastMethod = '';
00114 
00122     protected $_soapInputHeaders = array();
00123 
00131     protected $_permanentSoapInputHeaders = array();
00132 
00140     protected $_soapOutputHeaders = array();
00141 
00148     public function __construct($wsdl = null, $options = null)
00149     {
00150         if (!extension_loaded('soap')) {
00151             require_once 'Zend/Soap/Client/Exception.php';
00152             throw new Zend_Soap_Client_Exception('SOAP extension is not loaded.');
00153         }
00154 
00155         if ($wsdl !== null) {
00156             $this->setWsdl($wsdl);
00157         }
00158         if ($options !== null) {
00159             $this->setOptions($options);
00160         }
00161     }
00162 
00169     public function setWsdl($wsdl)
00170     {
00171         $this->_wsdl = $wsdl;
00172         $this->_soapClient = null;
00173 
00174         return $this;
00175     }
00176 
00182     public function getWsdl()
00183     {
00184         return $this->_wsdl;
00185     }
00186 
00196     public function setOptions($options)
00197     {
00198         if($options instanceof Zend_Config) {
00199             $options = $options->toArray();
00200         }
00201 
00202         foreach ($options as $key => $value) {
00203             switch ($key) {
00204                 case 'classmap':
00205                 case 'classMap':
00206                     $this->setClassmap($value);
00207                     break;
00208                 case 'encoding':
00209                     $this->setEncoding($value);
00210                     break;
00211                 case 'soapVersion':
00212                 case 'soap_version':
00213                     $this->setSoapVersion($value);
00214                     break;
00215                 case 'wsdl':
00216                     $this->setWsdl($value);
00217                     break;
00218                 case 'uri':
00219                     $this->setUri($value);
00220                     break;
00221                 case 'location':
00222                     $this->setLocation($value);
00223                     break;
00224                 case 'style':
00225                     $this->setStyle($value);
00226                     break;
00227                 case 'use':
00228                     $this->setEncodingMethod($value);
00229                     break;
00230                 case 'login':
00231                     $this->setHttpLogin($value);
00232                     break;
00233                 case 'password':
00234                     $this->setHttpPassword($value);
00235                     break;
00236                 case 'proxy_host':
00237                     $this->setProxyHost($value);
00238                     break;
00239                 case 'proxy_port':
00240                     $this->setProxyPort($value);
00241                     break;
00242                 case 'proxy_login':
00243                     $this->setProxyLogin($value);
00244                     break;
00245                 case 'proxy_password':
00246                     $this->setProxyPassword($value);
00247                     break;
00248                 case 'local_cert':
00249                     $this->setHttpsCertificate($value);
00250                     break;
00251                 case 'passphrase':
00252                     $this->setHttpsCertPassphrase($value);
00253                     break;
00254                 case 'compression':
00255                     $this->setCompressionOptions($value);
00256                     break;
00257                 case 'stream_context':
00258                     $this->setStreamContext($value);
00259                     break;
00260                 case 'features':
00261                     $this->setSoapFeatures($value);
00262                     break;
00263                 case 'cache_wsdl':
00264                     $this->setWsdlCache($value);
00265                     break;
00266                 case 'useragent':
00267                 case 'userAgent':
00268                 case 'user_agent':
00269                     $this->setUserAgent($value);
00270                     break;
00271 
00272                 // Not used now
00273                 // case 'connection_timeout':
00274                 //     $this->_connection_timeout = $value;
00275                 //    break;
00276 
00277                 default:
00278                     require_once 'Zend/Soap/Client/Exception.php';
00279                     throw new Zend_Soap_Client_Exception('Unknown SOAP client option');
00280                     break;
00281             }
00282         }
00283 
00284         return $this;
00285     }
00286 
00292     public function getOptions()
00293     {
00294         $options = array();
00295 
00296         $options['classmap']       = $this->getClassmap();
00297         $options['encoding']       = $this->getEncoding();
00298         $options['soap_version']   = $this->getSoapVersion();
00299         $options['wsdl']           = $this->getWsdl();
00300         $options['uri']            = $this->getUri();
00301         $options['location']       = $this->getLocation();
00302         $options['style']          = $this->getStyle();
00303         $options['use']            = $this->getEncodingMethod();
00304         $options['login']          = $this->getHttpLogin();
00305         $options['password']       = $this->getHttpPassword();
00306         $options['proxy_host']     = $this->getProxyHost();
00307         $options['proxy_port']     = $this->getProxyPort();
00308         $options['proxy_login']    = $this->getProxyLogin();
00309         $options['proxy_password'] = $this->getProxyPassword();
00310         $options['local_cert']     = $this->getHttpsCertificate();
00311         $options['passphrase']     = $this->getHttpsCertPassphrase();
00312         $options['compression']    = $this->getCompressionOptions();
00313         //$options['connection_timeout'] = $this->_connection_timeout;
00314         $options['stream_context'] = $this->getStreamContext();
00315         $options['cache_wsdl']     = $this->getWsdlCache();
00316         $options['features']       = $this->getSoapFeatures();
00317         $options['user_agent']     = $this->getUserAgent();
00318 
00319         foreach ($options as $key => $value) {
00320             /*
00321              * ugly hack as I don't know if checking for '=== null'
00322              * breaks some other option
00323              */
00324             if ($key == 'user_agent') {
00325                 if ($value === null) {
00326                     unset($options[$key]);
00327                 }
00328             } else {
00329                 if ($value == null) {
00330                     unset($options[$key]);
00331                 }
00332             }
00333         }
00334 
00335         return $options;
00336     }
00337 
00345     public function setSoapVersion($version)
00346     {
00347         if (!in_array($version, array(SOAP_1_1, SOAP_1_2))) {
00348             require_once 'Zend/Soap/Client/Exception.php';
00349             throw new Zend_Soap_Client_Exception('Invalid soap version specified. Use SOAP_1_1 or SOAP_1_2 constants.');
00350         }
00351         $this->_soapVersion = $version;
00352 
00353         $this->_soapClient = null;
00354 
00355         return $this;
00356     }
00357 
00363     public function getSoapVersion()
00364     {
00365         return $this->_soapVersion;
00366     }
00367 
00375     public function setClassmap(array $classmap)
00376     {
00377         foreach ($classmap as $type => $class) {
00378             if (!class_exists($class)) {
00379                 require_once 'Zend/Soap/Client/Exception.php';
00380                 throw new Zend_Soap_Client_Exception('Invalid class in class map');
00381             }
00382         }
00383 
00384         $this->_classmap = $classmap;
00385 
00386         $this->_soapClient = null;
00387 
00388         return $this;
00389     }
00390 
00396     public function getClassmap()
00397     {
00398         return $this->_classmap;
00399     }
00400 
00408     public function setEncoding($encoding)
00409     {
00410         if (!is_string($encoding)) {
00411             require_once 'Zend/Soap/Client/Exception.php';
00412             throw new Zend_Soap_Client_Exception('Invalid encoding specified');
00413         }
00414 
00415         $this->_encoding = $encoding;
00416 
00417         $this->_soapClient = null;
00418 
00419         return $this;
00420     }
00421 
00427     public function getEncoding()
00428     {
00429         return $this->_encoding;
00430     }
00431 
00439     public function validateUrn($urn)
00440     {
00441         $scheme = parse_url($urn, PHP_URL_SCHEME);
00442         if ($scheme === false || $scheme === null) {
00443             require_once 'Zend/Soap/Client/Exception.php';
00444             throw new Zend_Soap_Client_Exception('Invalid URN');
00445         }
00446 
00447         return true;
00448 
00449     }
00450 
00460     public function setUri($uri)
00461     {
00462         $this->validateUrn($uri);
00463         $this->_uri = $uri;
00464 
00465         $this->_soapClient = null;
00466 
00467         return $this;
00468     }
00469 
00475     public function getUri()
00476     {
00477         return $this->_uri;
00478     }
00479 
00489     public function setLocation($location)
00490     {
00491         $this->validateUrn($location);
00492         $this->_location = $location;
00493 
00494         $this->_soapClient = null;
00495 
00496         return $this;
00497     }
00498 
00504     public function getLocation()
00505     {
00506         return $this->_location;
00507     }
00508 
00516     public function setStyle($style)
00517     {
00518         if (!in_array($style, array(SOAP_RPC, SOAP_DOCUMENT))) {
00519             require_once 'Zend/Soap/Client/Exception.php';
00520             throw new Zend_Soap_Client_Exception('Invalid request style specified. Use SOAP_RPC or SOAP_DOCUMENT constants.');
00521         }
00522 
00523         $this->_style = $style;
00524 
00525         $this->_soapClient = null;
00526 
00527         return $this;
00528     }
00529 
00535     public function getStyle()
00536     {
00537         return $this->_style;
00538     }
00539 
00547     public function setEncodingMethod($use)
00548     {
00549         if (!in_array($use, array(SOAP_ENCODED, SOAP_LITERAL))) {
00550             require_once 'Zend/Soap/Client/Exception.php';
00551             throw new Zend_Soap_Client_Exception('Invalid message encoding method. Use SOAP_ENCODED or SOAP_LITERAL constants.');
00552         }
00553 
00554         $this->_use = $use;
00555 
00556         $this->_soapClient = null;
00557 
00558         return $this;
00559     }
00560 
00566     public function getEncodingMethod()
00567     {
00568         return $this->_use;
00569     }
00570 
00577     public function setHttpLogin($login)
00578     {
00579         $this->_login = $login;
00580 
00581         $this->_soapClient = null;
00582 
00583         return $this;
00584     }
00585 
00591     public function getHttpLogin()
00592     {
00593         return $this->_login;
00594     }
00595 
00602     public function setHttpPassword($password)
00603     {
00604         $this->_password = $password;
00605 
00606         $this->_soapClient = null;
00607 
00608         return $this;
00609     }
00610 
00616     public function getHttpPassword()
00617     {
00618         return $this->_password;
00619     }
00620 
00627     public function setProxyHost($proxyHost)
00628     {
00629         $this->_proxy_host = $proxyHost;
00630 
00631         $this->_soapClient = null;
00632 
00633         return $this;
00634     }
00635 
00641     public function getProxyHost()
00642     {
00643         return $this->_proxy_host;
00644     }
00645 
00652     public function setProxyPort($proxyPort)
00653     {
00654         $this->_proxy_port = (int)$proxyPort;
00655 
00656         $this->_soapClient = null;
00657 
00658         return $this;
00659     }
00660 
00666     public function getProxyPort()
00667     {
00668         return $this->_proxy_port;
00669     }
00670 
00677     public function setProxyLogin($proxyLogin)
00678     {
00679         $this->_proxy_login = $proxyLogin;
00680 
00681         $this->_soapClient = null;
00682 
00683         return $this;
00684     }
00685 
00691     public function getProxyLogin()
00692     {
00693         return $this->_proxy_login;
00694     }
00695 
00702     public function setProxyPassword($proxyPassword)
00703     {
00704         $this->_proxy_password = $proxyPassword;
00705 
00706         $this->_soapClient = null;
00707 
00708         return $this;
00709     }
00710 
00718     public function setHttpsCertificate($localCert)
00719     {
00720         if (!is_readable($localCert)) {
00721             require_once 'Zend/Soap/Client/Exception.php';
00722             throw new Zend_Soap_Client_Exception('Invalid HTTPS client certificate path.');
00723         }
00724 
00725         $this->_local_cert = $localCert;
00726 
00727         $this->_soapClient = null;
00728 
00729         return $this;
00730     }
00731 
00737     public function getHttpsCertificate()
00738     {
00739         return $this->_local_cert;
00740     }
00741 
00748     public function setHttpsCertPassphrase($passphrase)
00749     {
00750         $this->_passphrase = $passphrase;
00751 
00752         $this->_soapClient = null;
00753 
00754         return $this;
00755     }
00756 
00762     public function getHttpsCertPassphrase()
00763     {
00764         return $this->_passphrase;
00765     }
00766 
00773     public function setCompressionOptions($compressionOptions)
00774     {
00775         $this->_compression = $compressionOptions;
00776 
00777         $this->_soapClient = null;
00778 
00779         return $this;
00780     }
00781 
00787     public function getCompressionOptions()
00788     {
00789         return $this->_compression;
00790     }
00791 
00797     public function getProxyPassword()
00798     {
00799         return $this->_proxy_password;
00800     }
00801 
00807     public function setStreamContext($context)
00808     {
00809         if(!is_resource($context) || get_resource_type($context) !== "stream-context") {
00813             require_once "Zend/Soap/Client/Exception.php";
00814             throw new Zend_Soap_Client_Exception(
00815                 "Invalid stream context resource given."
00816             );
00817         }
00818 
00819         $this->_stream_context = $context;
00820         return $this;
00821     }
00822 
00828     public function getStreamContext()
00829     {
00830         return $this->_stream_context;
00831     }
00832 
00839     public function setSoapFeatures($feature)
00840     {
00841         $this->_features = $feature;
00842 
00843         $this->_soapClient = null;
00844         return $this;
00845     }
00846 
00852     public function getSoapFeatures()
00853     {
00854         return $this->_features;
00855     }
00856 
00863     public function setWsdlCache($options)
00864     {
00865         $this->_cache_wsdl = $options;
00866         return $this;
00867     }
00868 
00872     public function getWsdlCache()
00873     {
00874         return $this->_cache_wsdl;
00875     }
00876 
00883     public function setUserAgent($userAgent)
00884     {
00885         if ($userAgent === null) {
00886             $this->_user_agent = null;
00887         } else {
00888             $this->_user_agent = (string)$userAgent;
00889         }
00890         return $this;
00891     }
00892 
00898     public function getUserAgent()
00899     {
00900         return $this->_user_agent;
00901     }
00902 
00908     public function getLastRequest()
00909     {
00910         if ($this->_soapClient !== null) {
00911             return $this->_soapClient->__getLastRequest();
00912         }
00913 
00914         return '';
00915     }
00916 
00922     public function getLastResponse()
00923     {
00924         if ($this->_soapClient !== null) {
00925             return $this->_soapClient->__getLastResponse();
00926         }
00927 
00928         return '';
00929     }
00930 
00936     public function getLastRequestHeaders()
00937     {
00938         if ($this->_soapClient !== null) {
00939             return $this->_soapClient->__getLastRequestHeaders();
00940         }
00941 
00942         return '';
00943     }
00944 
00950     public function getLastResponseHeaders()
00951     {
00952         if ($this->_soapClient !== null) {
00953             return $this->_soapClient->__getLastResponseHeaders();
00954         }
00955 
00956         return '';
00957     }
00958 
00964     public function getLastMethod()
00965     {
00966         return $this->_lastMethod;
00967     }
00968 
00983     public function _doRequest(Zend_Soap_Client_Common $client, $request, $location, $action, $version, $one_way = null)
00984     {
00985         // Perform request as is
00986         if ($one_way == null) {
00987             return call_user_func(array($client,'SoapClient::__doRequest'), $request, $location, $action, $version);
00988         } else {
00989             return call_user_func(array($client,'SoapClient::__doRequest'), $request, $location, $action, $version, $one_way);
00990         }
00991     }
00992 
00998     protected function _initSoapClientObject()
00999     {
01000         $wsdl = $this->getWsdl();
01001         $options = array_merge($this->getOptions(), array('trace' => true));
01002 
01003         if ($wsdl == null) {
01004             if (!isset($options['location'])) {
01005                 require_once 'Zend/Soap/Client/Exception.php';
01006                 throw new Zend_Soap_Client_Exception('\'location\' parameter is required in non-WSDL mode.');
01007             }
01008             if (!isset($options['uri'])) {
01009                 require_once 'Zend/Soap/Client/Exception.php';
01010                 throw new Zend_Soap_Client_Exception('\'uri\' parameter is required in non-WSDL mode.');
01011             }
01012         } else {
01013             if (isset($options['use'])) {
01014                 require_once 'Zend/Soap/Client/Exception.php';
01015                 throw new Zend_Soap_Client_Exception('\'use\' parameter only works in non-WSDL mode.');
01016             }
01017             if (isset($options['style'])) {
01018                 require_once 'Zend/Soap/Client/Exception.php';
01019                 throw new Zend_Soap_Client_Exception('\'style\' parameter only works in non-WSDL mode.');
01020             }
01021         }
01022         unset($options['wsdl']);
01023 
01024         $this->_soapClient = new Zend_Soap_Client_Common(array($this, '_doRequest'), $wsdl, $options);
01025     }
01026 
01027 
01035     protected function _preProcessArguments($arguments)
01036     {
01037         // Do nothing
01038         return $arguments;
01039     }
01040 
01048     protected function _preProcessResult($result)
01049     {
01050         // Do nothing
01051         return $result;
01052     }
01053 
01061     public function addSoapInputHeader(SoapHeader $header, $permanent = false)
01062     {
01063         if ($permanent) {
01064             $this->_permanentSoapInputHeaders[] = $header;
01065         } else {
01066             $this->_soapInputHeaders[] = $header;
01067         }
01068 
01069         return $this;
01070     }
01071 
01077     public function resetSoapInputHeaders()
01078     {
01079         $this->_permanentSoapInputHeaders = array();
01080         $this->_soapInputHeaders = array();
01081 
01082         return $this;
01083     }
01084 
01090     public function getLastSoapOutputHeaderObjects()
01091     {
01092         return $this->_soapOutputHeaders;
01093     }
01094 
01102     public function __call($name, $arguments)
01103     {
01104         $soapClient = $this->getSoapClient();
01105 
01106         $this->_lastMethod = $name;
01107 
01108         $soapHeaders = array_merge($this->_permanentSoapInputHeaders, $this->_soapInputHeaders);
01109         $result = $soapClient->__soapCall($name,
01110                                                  $this->_preProcessArguments($arguments),
01111                                                  null, /* Options are already set to the SOAP client object */
01112                                                  (count($soapHeaders) > 0)? $soapHeaders : null,
01113                                                  $this->_soapOutputHeaders);
01114 
01115         // Reset non-permanent input headers
01116         $this->_soapInputHeaders = array();
01117 
01118         return $this->_preProcessResult($result);
01119     }
01120 
01121 
01128     public function getFunctions()
01129     {
01130         if ($this->getWsdl() == null) {
01131             require_once 'Zend/Soap/Client/Exception.php';
01132             throw new Zend_Soap_Client_Exception('\'getFunctions\' method is available only in WSDL mode.');
01133         }
01134 
01135         $soapClient = $this->getSoapClient();
01136         return $soapClient->__getFunctions();
01137     }
01138 
01139 
01152     public function getTypes()
01153     {
01154         if ($this->getWsdl() == null) {
01155             require_once 'Zend/Soap/Client/Exception.php';
01156             throw new Zend_Soap_Client_Exception('\'getTypes\' method is available only in WSDL mode.');
01157         }
01158 
01159         $soapClient = $this->getSoapClient();
01160 
01161         return $soapClient->__getTypes();
01162     }
01163 
01168     public function setSoapClient(SoapClient $soapClient)
01169     {
01170         $this->_soapClient = $soapClient;
01171         return $this;
01172     }
01173 
01177     public function getSoapClient()
01178     {
01179         if ($this->_soapClient == null) {
01180             $this->_initSoapClientObject();
01181         }
01182         return $this->_soapClient;
01183     }
01184 
01190     public function setCookie($cookieName, $cookieValue=null)
01191     {
01192         $soapClient = $this->getSoapClient();
01193         $soapClient->__setCookie($cookieName, $cookieValue);
01194         return $this;
01195     }
01196 }
 All Data Structures Namespaces Files Functions Variables Enumerations