*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Soap / Client.php
blob34a1406862d16e5eff5ec7ff6d336bbe59603487
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
15 * @category Zend
16 * @package Zend_Soap
17 * @subpackage Client
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: Client.php 16971 2009-07-22 18:05:45Z mikaelkael $
23 /** Zend_Soap_Server */
24 require_once 'Zend/Soap/Server.php';
26 /** Zend_Soap_Client_Local */
27 require_once 'Zend/Soap/Client/Local.php';
29 /** Zend_Soap_Client_Common */
30 require_once 'Zend/Soap/Client/Common.php';
32 /**
33 * Zend_Soap_Client
35 * @category Zend
36 * @package Zend_Soap
37 * @subpackage Client
38 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
39 * @license http://framework.zend.com/license/new-bsd New BSD License
41 class Zend_Soap_Client
43 /**
44 * Encoding
45 * @var string
47 protected $_encoding = 'UTF-8';
49 /**
50 * Array of SOAP type => PHP class pairings for handling return/incoming values
51 * @var array
53 protected $_classmap = null;
55 /**
56 * Registered fault exceptions
57 * @var array
59 protected $_faultExceptions = array();
61 /**
62 * SOAP version to use; SOAP_1_2 by default, to allow processing of headers
63 * @var int
65 protected $_soapVersion = SOAP_1_2;
67 /** Set of other SoapClient options */
68 protected $_uri = null;
69 protected $_location = null;
70 protected $_style = null;
71 protected $_use = null;
72 protected $_login = null;
73 protected $_password = null;
74 protected $_proxy_host = null;
75 protected $_proxy_port = null;
76 protected $_proxy_login = null;
77 protected $_proxy_password = null;
78 protected $_local_cert = null;
79 protected $_passphrase = null;
80 protected $_compression = null;
81 protected $_connection_timeout = null;
82 protected $_stream_context = null;
83 protected $_features = null;
84 protected $_cache_wsdl = null;
86 /**
87 * WSDL used to access server
88 * It also defines Zend_Soap_Client working mode (WSDL vs non-WSDL)
90 * @var string
92 protected $_wsdl = null;
94 /**
95 * SoapClient object
97 * @var SoapClient
99 protected $_soapClient;
102 * Last invoked method
104 * @var string
106 protected $_lastMethod = '';
109 * SOAP request headers.
111 * Array of SoapHeader objects
113 * @var array
115 protected $_soapInputHeaders = array();
118 * Permanent SOAP request headers (shared between requests).
120 * Array of SoapHeader objects
122 * @var array
124 protected $_permanentSoapInputHeaders = array();
127 * Output SOAP headers.
129 * Array of SoapHeader objects
131 * @var array
133 protected $_soapOutputHeaders = array();
136 * Constructor
138 * @param string $wsdl
139 * @param array $options
141 public function __construct($wsdl = null, $options = null)
143 if (!extension_loaded('soap')) {
144 require_once 'Zend/Soap/Client/Exception.php';
145 throw new Zend_Soap_Client_Exception('SOAP extension is not loaded.');
148 if ($wsdl !== null) {
149 $this->setWsdl($wsdl);
151 if ($options !== null) {
152 $this->setOptions($options);
157 * Set wsdl
159 * @param string $wsdl
160 * @return Zend_Soap_Client
162 public function setWsdl($wsdl)
164 $this->_wsdl = $wsdl;
165 $this->_soapClient = null;
167 return $this;
171 * Get wsdl
173 * @return string
175 public function getWsdl()
177 return $this->_wsdl;
181 * Set Options
183 * Allows setting options as an associative array of option => value pairs.
185 * @param array|Zend_Config $options
186 * @return Zend_Soap_Client
187 * @throws Zend_SoapClient_Exception
189 public function setOptions($options)
191 if($options instanceof Zend_Config) {
192 $options = $options->toArray();
195 foreach ($options as $key => $value) {
196 switch ($key) {
197 case 'classmap':
198 case 'classMap':
199 $this->setClassmap($value);
200 break;
201 case 'encoding':
202 $this->setEncoding($value);
203 break;
204 case 'soapVersion':
205 case 'soap_version':
206 $this->setSoapVersion($value);
207 break;
208 case 'wsdl':
209 $this->setWsdl($value);
210 break;
211 case 'uri':
212 $this->setUri($value);
213 break;
214 case 'location':
215 $this->setLocation($value);
216 break;
217 case 'style':
218 $this->setStyle($value);
219 break;
220 case 'use':
221 $this->setEncodingMethod($value);
222 break;
223 case 'login':
224 $this->setHttpLogin($value);
225 break;
226 case 'password':
227 $this->setHttpPassword($value);
228 break;
229 case 'proxy_host':
230 $this->setProxyHost($value);
231 break;
232 case 'proxy_port':
233 $this->setProxyPort($value);
234 break;
235 case 'proxy_login':
236 $this->setProxyLogin($value);
237 break;
238 case 'proxy_password':
239 $this->setProxyPassword($value);
240 break;
241 case 'local_cert':
242 $this->setHttpsCertificate($value);
243 break;
244 case 'passphrase':
245 $this->setHttpsCertPassphrase($value);
246 break;
247 case 'compression':
248 $this->setCompressionOptions($value);
249 break;
250 case 'stream_context':
251 $this->setStreamContext($value);
252 break;
253 case 'features':
254 $this->setSoapFeatures($value);
255 break;
256 case 'cache_wsdl':
257 $this->setWsdlCache($value);
258 break;
260 // Not used now
261 // case 'connection_timeout':
262 // $this->_connection_timeout = $value;
263 // break;
265 default:
266 require_once 'Zend/Soap/Client/Exception.php';
267 throw new Zend_Soap_Client_Exception('Unknown SOAP client option');
268 break;
272 return $this;
276 * Return array of options suitable for using with SoapClient constructor
278 * @return array
280 public function getOptions()
282 $options = array();
284 $options['classmap'] = $this->getClassmap();
285 $options['encoding'] = $this->getEncoding();
286 $options['soap_version'] = $this->getSoapVersion();
287 $options['wsdl'] = $this->getWsdl();
288 $options['uri'] = $this->getUri();
289 $options['location'] = $this->getLocation();
290 $options['style'] = $this->getStyle();
291 $options['use'] = $this->getEncodingMethod();
292 $options['login'] = $this->getHttpLogin();
293 $options['password'] = $this->getHttpPassword();
294 $options['proxy_host'] = $this->getProxyHost();
295 $options['proxy_port'] = $this->getProxyPort();
296 $options['proxy_login'] = $this->getProxyLogin();
297 $options['proxy_password'] = $this->getProxyPassword();
298 $options['local_cert'] = $this->getHttpsCertificate();
299 $options['passphrase'] = $this->getHttpsCertPassphrase();
300 $options['compression'] = $this->getCompressionOptions();
301 //$options['connection_timeout'] = $this->_connection_timeout;
302 $options['stream_context'] = $this->getStreamContext();
303 $options['cache_wsdl'] = $this->getWsdlCache();
304 $options['features'] = $this->getSoapFeatures();
306 foreach ($options as $key => $value) {
307 if ($value == null) {
308 unset($options[$key]);
312 return $options;
316 * Set SOAP version
318 * @param int $version One of the SOAP_1_1 or SOAP_1_2 constants
319 * @return Zend_Soap_Client
320 * @throws Zend_Soap_Client_Exception with invalid soap version argument
322 public function setSoapVersion($version)
324 if (!in_array($version, array(SOAP_1_1, SOAP_1_2))) {
325 require_once 'Zend/Soap/Client/Exception.php';
326 throw new Zend_Soap_Client_Exception('Invalid soap version specified. Use SOAP_1_1 or SOAP_1_2 constants.');
328 $this->_soapVersion = $version;
330 $this->_soapClient = null;
332 return $this;
336 * Get SOAP version
338 * @return int
340 public function getSoapVersion()
342 return $this->_soapVersion;
346 * Set classmap
348 * @param array $classmap
349 * @return Zend_Soap_Client
350 * @throws Zend_Soap_Client_Exception for any invalid class in the class map
352 public function setClassmap(array $classmap)
354 foreach ($classmap as $type => $class) {
355 if (!class_exists($class)) {
356 require_once 'Zend/Soap/Client/Exception.php';
357 throw new Zend_Soap_Client_Exception('Invalid class in class map');
361 $this->_classmap = $classmap;
363 $this->_soapClient = null;
365 return $this;
369 * Retrieve classmap
371 * @return mixed
373 public function getClassmap()
375 return $this->_classmap;
379 * Set encoding
381 * @param string $encoding
382 * @return Zend_Soap_Client
383 * @throws Zend_Soap_Client_Exception with invalid encoding argument
385 public function setEncoding($encoding)
387 if (!is_string($encoding)) {
388 require_once 'Zend/Soap/Client/Exception.php';
389 throw new Zend_Soap_Client_Exception('Invalid encoding specified');
392 $this->_encoding = $encoding;
394 $this->_soapClient = null;
396 return $this;
400 * Get encoding
402 * @return string
404 public function getEncoding()
406 return $this->_encoding;
410 * Check for valid URN
412 * @param string $urn
413 * @return true
414 * @throws Zend_Soap_Client_Exception on invalid URN
416 public function validateUrn($urn)
418 $segs = parse_url($urn);
419 if (isset($segs['scheme'])) {
420 return true;
423 require_once 'Zend/Soap/Client/Exception.php';
424 throw new Zend_Soap_Client_Exception('Invalid URN');
428 * Set URI
430 * URI in Web Service the target namespace
432 * @param string $uri
433 * @return Zend_Soap_Client
434 * @throws Zend_Soap_Client_Exception with invalid uri argument
436 public function setUri($uri)
438 $this->validateUrn($uri);
439 $this->_uri = $uri;
441 $this->_soapClient = null;
443 return $this;
447 * Retrieve URI
449 * @return string
451 public function getUri()
453 return $this->_uri;
457 * Set Location
459 * URI in Web Service the target namespace
461 * @param string $location
462 * @return Zend_Soap_Client
463 * @throws Zend_Soap_Client_Exception with invalid uri argument
465 public function setLocation($location)
467 $this->validateUrn($location);
468 $this->_location = $location;
470 $this->_soapClient = null;
472 return $this;
476 * Retrieve URI
478 * @return string
480 public function getLocation()
482 return $this->_location;
486 * Set request style
488 * @param int $style One of the SOAP_RPC or SOAP_DOCUMENT constants
489 * @return Zend_Soap_Client
490 * @throws Zend_Soap_Client_Exception with invalid style argument
492 public function setStyle($style)
494 if (!in_array($style, array(SOAP_RPC, SOAP_DOCUMENT))) {
495 require_once 'Zend/Soap/Client/Exception.php';
496 throw new Zend_Soap_Client_Exception('Invalid request style specified. Use SOAP_RPC or SOAP_DOCUMENT constants.');
499 $this->_style = $style;
501 $this->_soapClient = null;
503 return $this;
507 * Get request style
509 * @return int
511 public function getStyle()
513 return $this->_style;
517 * Set message encoding method
519 * @param int $use One of the SOAP_ENCODED or SOAP_LITERAL constants
520 * @return Zend_Soap_Client
521 * @throws Zend_Soap_Client_Exception with invalid message encoding method argument
523 public function setEncodingMethod($use)
525 if (!in_array($use, array(SOAP_ENCODED, SOAP_LITERAL))) {
526 require_once 'Zend/Soap/Client/Exception.php';
527 throw new Zend_Soap_Client_Exception('Invalid message encoding method. Use SOAP_ENCODED or SOAP_LITERAL constants.');
530 $this->_use = $use;
532 $this->_soapClient = null;
534 return $this;
538 * Get message encoding method
540 * @return int
542 public function getEncodingMethod()
544 return $this->_use;
548 * Set HTTP login
550 * @param string $login
551 * @return Zend_Soap_Client
553 public function setHttpLogin($login)
555 $this->_login = $login;
557 $this->_soapClient = null;
559 return $this;
563 * Retrieve HTTP Login
565 * @return string
567 public function getHttpLogin()
569 return $this->_login;
573 * Set HTTP password
575 * @param string $password
576 * @return Zend_Soap_Client
578 public function setHttpPassword($password)
580 $this->_password = $password;
582 $this->_soapClient = null;
584 return $this;
588 * Retrieve HTTP Password
590 * @return string
592 public function getHttpPassword()
594 return $this->_password;
598 * Set proxy host
600 * @param string $proxyHost
601 * @return Zend_Soap_Client
603 public function setProxyHost($proxyHost)
605 $this->_proxy_host = $proxyHost;
607 $this->_soapClient = null;
609 return $this;
613 * Retrieve proxy host
615 * @return string
617 public function getProxyHost()
619 return $this->_proxy_host;
623 * Set proxy port
625 * @param int $proxyPort
626 * @return Zend_Soap_Client
628 public function setProxyPort($proxyPort)
630 $this->_proxy_port = (int)$proxyPort;
632 $this->_soapClient = null;
634 return $this;
638 * Retrieve proxy port
640 * @return int
642 public function getProxyPort()
644 return $this->_proxy_port;
648 * Set proxy login
650 * @param string $proxyLogin
651 * @return Zend_Soap_Client
653 public function setProxyLogin($proxyLogin)
655 $this->_proxy_login = $proxyLogin;
657 $this->_soapClient = null;
659 return $this;
663 * Retrieve proxy login
665 * @return string
667 public function getProxyLogin()
669 return $this->_proxy_login;
673 * Set proxy password
675 * @param string $proxyLogin
676 * @return Zend_Soap_Client
678 public function setProxyPassword($proxyPassword)
680 $this->_proxy_password = $proxyPassword;
682 $this->_soapClient = null;
684 return $this;
688 * Set HTTPS client certificate path
690 * @param string $localCert local certificate path
691 * @return Zend_Soap_Client
692 * @throws Zend_Soap_Client_Exception with invalid local certificate path argument
694 public function setHttpsCertificate($localCert)
696 if (!is_readable($localCert)) {
697 require_once 'Zend/Soap/Client/Exception.php';
698 throw new Zend_Soap_Client_Exception('Invalid HTTPS client certificate path.');
701 $this->_local_cert = $localCert;
703 $this->_soapClient = null;
705 return $this;
709 * Get HTTPS client certificate path
711 * @return string
713 public function getHttpsCertificate()
715 return $this->_local_cert;
719 * Set HTTPS client certificate passphrase
721 * @param string $passphrase
722 * @return Zend_Soap_Client
724 public function setHttpsCertPassphrase($passphrase)
726 $this->_passphrase = $passphrase;
728 $this->_soapClient = null;
730 return $this;
734 * Get HTTPS client certificate passphrase
736 * @return string
738 public function getHttpsCertPassphrase()
740 return $this->_passphrase;
744 * Set compression options
746 * @param int $compressionOptions
747 * @return Zend_Soap_Client
749 public function setCompressionOptions($compressionOptions)
751 $this->_compression = $compressionOptions;
753 $this->_soapClient = null;
755 return $this;
759 * Get Compression options
761 * @return int
763 public function getCompressionOptions()
765 return $this->_compression;
769 * Retrieve proxy password
771 * @return string
773 public function getProxyPassword()
775 return $this->_proxy_password;
779 * Set Stream Context
781 * @return Zend_Soap_Client
783 public function setStreamContext($context)
785 if(!is_resource($context) || get_resource_type($context) !== "stream-context") {
787 * @see Zend_Soap_Client_Exception
789 require_once "Zend/Soap/Client/Exception.php";
790 throw new Zend_Soap_Client_Exception(
791 "Invalid stream context resource given."
795 $this->_stream_context = $context;
796 return $this;
800 * Get Stream Context
802 * @return resource
804 public function getStreamContext()
806 return $this->_stream_context;
810 * Set the SOAP Feature options.
812 * @param string|int $feature
813 * @return Zend_Soap_Client
815 public function setSoapFeatures($feature)
817 $this->_features = $feature;
819 $this->_soapClient = null;
820 return $this;
824 * Return current SOAP Features options
826 * @return int
828 public function getSoapFeatures()
830 return $this->_features;
834 * Set the SOAP Wsdl Caching Options
836 * @param string|int|boolean $caching
837 * @return Zend_Soap_Client
839 public function setWsdlCache($options)
841 $this->_cache_wsdl = $options;
842 return $this;
846 * Get current SOAP Wsdl Caching option
848 public function getWsdlCache()
850 return $this->_cache_wsdl;
854 * Retrieve request XML
856 * @return string
858 public function getLastRequest()
860 if ($this->_soapClient !== null) {
861 return $this->_soapClient->__getLastRequest();
864 return '';
868 * Get response XML
870 * @return string
872 public function getLastResponse()
874 if ($this->_soapClient !== null) {
875 return $this->_soapClient->__getLastResponse();
878 return '';
882 * Retrieve request headers
884 * @return string
886 public function getLastRequestHeaders()
888 if ($this->_soapClient !== null) {
889 return $this->_soapClient->__getLastRequestHeaders();
892 return '';
896 * Retrieve response headers (as string)
898 * @return string
900 public function getLastResponseHeaders()
902 if ($this->_soapClient !== null) {
903 return $this->_soapClient->__getLastResponseHeaders();
906 return '';
910 * Retrieve last invoked method
912 * @return string
914 public function getLastMethod()
916 return $this->_lastMethod;
920 * Do request proxy method.
922 * May be overridden in subclasses
924 * @internal
925 * @param Zend_Soap_Client_Common $client
926 * @param string $request
927 * @param string $location
928 * @param string $action
929 * @param int $version
930 * @param int $one_way
931 * @return mixed
933 public function _doRequest(Zend_Soap_Client_Common $client, $request, $location, $action, $version, $one_way = null)
935 // Perform request as is
936 if ($one_way == null) {
937 return call_user_func(array($client,'SoapClient::__doRequest'), $request, $location, $action, $version);
938 } else {
939 return call_user_func(array($client,'SoapClient::__doRequest'), $request, $location, $action, $version, $one_way);
944 * Initialize SOAP Client object
946 * @throws Zend_Soap_Client_Exception
948 protected function _initSoapClientObject()
950 $wsdl = $this->getWsdl();
951 $options = array_merge($this->getOptions(), array('trace' => true));
953 if ($wsdl == null) {
954 if (!isset($options['location'])) {
955 require_once 'Zend/Soap/Client/Exception.php';
956 throw new Zend_Soap_Client_Exception('\'location\' parameter is required in non-WSDL mode.');
958 if (!isset($options['uri'])) {
959 require_once 'Zend/Soap/Client/Exception.php';
960 throw new Zend_Soap_Client_Exception('\'uri\' parameter is required in non-WSDL mode.');
962 } else {
963 if (isset($options['use'])) {
964 require_once 'Zend/Soap/Client/Exception.php';
965 throw new Zend_Soap_Client_Exception('\'use\' parameter only works in non-WSDL mode.');
967 if (isset($options['style'])) {
968 require_once 'Zend/Soap/Client/Exception.php';
969 throw new Zend_Soap_Client_Exception('\'style\' parameter only works in non-WSDL mode.');
972 unset($options['wsdl']);
974 $this->_soapClient = new Zend_Soap_Client_Common(array($this, '_doRequest'), $wsdl, $options);
979 * Perform arguments pre-processing
981 * My be overridden in descendant classes
983 * @param array $arguments
985 protected function _preProcessArguments($arguments)
987 // Do nothing
988 return $arguments;
992 * Perform result pre-processing
994 * My be overridden in descendant classes
996 * @param array $arguments
998 protected function _preProcessResult($result)
1000 // Do nothing
1001 return $result;
1005 * Add SOAP input header
1007 * @param SoapHeader $header
1008 * @param boolean $permanent
1009 * @return Zend_Soap_Client
1011 public function addSoapInputHeader(SoapHeader $header, $permanent = false)
1013 if ($permanent) {
1014 $this->_permanentSoapInputHeaders[] = $header;
1015 } else {
1016 $this->_soapInputHeaders[] = $header;
1019 return $this;
1023 * Reset SOAP input headers
1025 * @return Zend_Soap_Client
1027 public function resetSoapInputHeaders()
1029 $this->_permanentSoapInputHeaders = array();
1030 $this->_soapInputHeaders = array();
1032 return $this;
1036 * Get last SOAP output headers
1038 * @return array
1040 public function getLastSoapOutputHeaderObjects()
1042 return $this->_soapOutputHeaders;
1046 * Perform a SOAP call
1048 * @param string $name
1049 * @param array $arguments
1050 * @return mixed
1052 public function __call($name, $arguments)
1054 $soapClient = $this->getSoapClient();
1056 $this->_lastMethod = $name;
1058 $soapHeaders = array_merge($this->_permanentSoapInputHeaders, $this->_soapInputHeaders);
1059 $result = $soapClient->__soapCall($name,
1060 $this->_preProcessArguments($arguments),
1061 null, /* Options are already set to the SOAP client object */
1062 (count($soapHeaders) > 0)? $soapHeaders : null,
1063 $this->_soapOutputHeaders);
1065 // Reset non-permanent input headers
1066 $this->_soapInputHeaders = array();
1068 return $this->_preProcessResult($result);
1073 * Return a list of available functions
1075 * @return array
1076 * @throws Zend_Soap_Client_Exception
1078 public function getFunctions()
1080 if ($this->getWsdl() == null) {
1081 require_once 'Zend/Soap/Client/Exception.php';
1082 throw new Zend_Soap_Client_Exception('\'getFunctions\' method is available only in WSDL mode.');
1085 $soapClient = $this->getSoapClient();
1086 return $soapClient->__getFunctions();
1091 * Get used types.
1093 * @return array
1097 * Return a list of SOAP types
1099 * @return array
1100 * @throws Zend_Soap_Client_Exception
1102 public function getTypes()
1104 if ($this->getWsdl() == null) {
1105 require_once 'Zend/Soap/Client/Exception.php';
1106 throw new Zend_Soap_Client_Exception('\'getTypes\' method is available only in WSDL mode.');
1109 $soapClient = $this->getSoapClient();
1111 return $soapClient->__getTypes();
1115 * @param SoapClient $soapClient
1116 * @return Zend_Soap_Client
1118 public function setSoapClient(SoapClient $soapClient)
1120 $this->_soapClient = $soapClient;
1121 return $this;
1125 * @return SoapClient
1127 public function getSoapClient()
1129 if ($this->_soapClient == null) {
1130 $this->_initSoapClientObject();
1132 return $this->_soapClient;
1136 * @param string $name
1137 * @param string $value
1138 * @return Zend_Soap_Client
1140 public function setCookie($cookieName, $cookieValue=null)
1142 $soapClient = $this->getSoapClient();
1143 $soapClient->__setCookie($cookieName, $cookieValue);
1144 return $this;