Client.php 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  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.
  14. *
  15. * @category Zend
  16. * @package Zend_Soap
  17. * @subpackage Client
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /** Zend_Soap_Server */
  22. require_once 'Zend/Soap/Server.php';
  23. /** Zend_Soap_Client_Local */
  24. require_once 'Zend/Soap/Client/Local.php';
  25. /** Zend_Soap_Client_Common */
  26. require_once 'Zend/Soap/Client/Common.php';
  27. /**
  28. * Zend_Soap_Client
  29. *
  30. * @category Zend
  31. * @package Zend_Soap
  32. * @subpackage Client
  33. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_Soap_Client
  37. {
  38. /**
  39. * Encoding
  40. * @var string
  41. */
  42. protected $_encoding = 'UTF-8';
  43. /**
  44. * Array of SOAP type => PHP class pairings for handling return/incoming values
  45. * @var array
  46. */
  47. protected $_classmap = null;
  48. /**
  49. * Registered fault exceptions
  50. * @var array
  51. */
  52. protected $_faultExceptions = array();
  53. /**
  54. * SOAP version to use; SOAP_1_2 by default, to allow processing of headers
  55. * @var int
  56. */
  57. protected $_soapVersion = SOAP_1_2;
  58. /** Set of other SoapClient options */
  59. protected $_uri = null;
  60. protected $_location = null;
  61. protected $_style = null;
  62. protected $_use = null;
  63. protected $_login = null;
  64. protected $_password = null;
  65. protected $_proxy_host = null;
  66. protected $_proxy_port = null;
  67. protected $_proxy_login = null;
  68. protected $_proxy_password = null;
  69. protected $_local_cert = null;
  70. protected $_passphrase = null;
  71. protected $_compression = null;
  72. protected $_connection_timeout = null;
  73. protected $_stream_context = null;
  74. protected $_features = null;
  75. protected $_cache_wsdl = null;
  76. /**
  77. * WSDL used to access server
  78. * It also defines Zend_Soap_Client working mode (WSDL vs non-WSDL)
  79. *
  80. * @var string
  81. */
  82. protected $_wsdl = null;
  83. /**
  84. * SoapClient object
  85. *
  86. * @var SoapClient
  87. */
  88. protected $_soapClient;
  89. /**
  90. * Last invoked method
  91. *
  92. * @var string
  93. */
  94. protected $_lastMethod = '';
  95. /**
  96. * SOAP request headers.
  97. *
  98. * Array of SoapHeader objects
  99. *
  100. * @var array
  101. */
  102. protected $_soapInputHeaders = array();
  103. /**
  104. * Permanent SOAP request headers (shared between requests).
  105. *
  106. * Array of SoapHeader objects
  107. *
  108. * @var array
  109. */
  110. protected $_permanentSoapInputHeaders = array();
  111. /**
  112. * Output SOAP headers.
  113. *
  114. * Array of SoapHeader objects
  115. *
  116. * @var array
  117. */
  118. protected $_soapOutputHeaders = array();
  119. /**
  120. * Constructor
  121. *
  122. * @param string $wsdl
  123. * @param array $options
  124. */
  125. public function __construct($wsdl = null, $options = null)
  126. {
  127. if (!extension_loaded('soap')) {
  128. require_once 'Zend/Soap/Client/Exception.php';
  129. throw new Zend_Soap_Client_Exception('SOAP extension is not loaded.');
  130. }
  131. if ($wsdl !== null) {
  132. $this->setWsdl($wsdl);
  133. }
  134. if ($options !== null) {
  135. $this->setOptions($options);
  136. }
  137. }
  138. /**
  139. * Set wsdl
  140. *
  141. * @param string $wsdl
  142. * @return Zend_Soap_Client
  143. */
  144. public function setWsdl($wsdl)
  145. {
  146. $this->_wsdl = $wsdl;
  147. $this->_soapClient = null;
  148. return $this;
  149. }
  150. /**
  151. * Get wsdl
  152. *
  153. * @return string
  154. */
  155. public function getWsdl()
  156. {
  157. return $this->_wsdl;
  158. }
  159. /**
  160. * Set Options
  161. *
  162. * Allows setting options as an associative array of option => value pairs.
  163. *
  164. * @param array|Zend_Config $options
  165. * @return Zend_Soap_Client
  166. * @throws Zend_SoapClient_Exception
  167. */
  168. public function setOptions($options)
  169. {
  170. if($options instanceof Zend_Config) {
  171. $options = $options->toArray();
  172. }
  173. foreach ($options as $key => $value) {
  174. switch ($key) {
  175. case 'classmap':
  176. case 'classMap':
  177. $this->setClassmap($value);
  178. break;
  179. case 'encoding':
  180. $this->setEncoding($value);
  181. break;
  182. case 'soapVersion':
  183. case 'soap_version':
  184. $this->setSoapVersion($value);
  185. break;
  186. case 'wsdl':
  187. $this->setWsdl($value);
  188. break;
  189. case 'uri':
  190. $this->setUri($value);
  191. break;
  192. case 'location':
  193. $this->setLocation($value);
  194. break;
  195. case 'style':
  196. $this->setStyle($value);
  197. break;
  198. case 'use':
  199. $this->setEncodingMethod($value);
  200. break;
  201. case 'login':
  202. $this->setHttpLogin($value);
  203. break;
  204. case 'password':
  205. $this->setHttpPassword($value);
  206. break;
  207. case 'proxy_host':
  208. $this->setProxyHost($value);
  209. break;
  210. case 'proxy_port':
  211. $this->setProxyPort($value);
  212. break;
  213. case 'proxy_login':
  214. $this->setProxyLogin($value);
  215. break;
  216. case 'proxy_password':
  217. $this->setProxyPassword($value);
  218. break;
  219. case 'local_cert':
  220. $this->setHttpsCertificate($value);
  221. break;
  222. case 'passphrase':
  223. $this->setHttpsCertPassphrase($value);
  224. break;
  225. case 'compression':
  226. $this->setCompressionOptions($value);
  227. break;
  228. case 'stream_context':
  229. $this->setStreamContext($value);
  230. break;
  231. case 'features':
  232. $this->setSoapFeatures($value);
  233. break;
  234. case 'cache_wsdl':
  235. $this->setWsdlCache($value);
  236. break;
  237. // Not used now
  238. // case 'connection_timeout':
  239. // $this->_connection_timeout = $value;
  240. // break;
  241. default:
  242. require_once 'Zend/Soap/Client/Exception.php';
  243. throw new Zend_Soap_Client_Exception('Unknown SOAP client option');
  244. break;
  245. }
  246. }
  247. return $this;
  248. }
  249. /**
  250. * Return array of options suitable for using with SoapClient constructor
  251. *
  252. * @return array
  253. */
  254. public function getOptions()
  255. {
  256. $options = array();
  257. $options['classmap'] = $this->getClassmap();
  258. $options['encoding'] = $this->getEncoding();
  259. $options['soap_version'] = $this->getSoapVersion();
  260. $options['wsdl'] = $this->getWsdl();
  261. $options['uri'] = $this->getUri();
  262. $options['location'] = $this->getLocation();
  263. $options['style'] = $this->getStyle();
  264. $options['use'] = $this->getEncodingMethod();
  265. $options['login'] = $this->getHttpLogin();
  266. $options['password'] = $this->getHttpPassword();
  267. $options['proxy_host'] = $this->getProxyHost();
  268. $options['proxy_port'] = $this->getProxyPort();
  269. $options['proxy_login'] = $this->getProxyLogin();
  270. $options['proxy_password'] = $this->getProxyPassword();
  271. $options['local_cert'] = $this->getHttpsCertificate();
  272. $options['passphrase'] = $this->getHttpsCertPassphrase();
  273. $options['compression'] = $this->getCompressionOptions();
  274. //$options['connection_timeout'] = $this->_connection_timeout;
  275. $options['stream_context'] = $this->getStreamContext();
  276. $options['cache_wsdl'] = $this->getWsdlCache();
  277. $options['features'] = $this->getSoapFeatures();
  278. foreach ($options as $key => $value) {
  279. if ($value == null) {
  280. unset($options[$key]);
  281. }
  282. }
  283. return $options;
  284. }
  285. /**
  286. * Set SOAP version
  287. *
  288. * @param int $version One of the SOAP_1_1 or SOAP_1_2 constants
  289. * @return Zend_Soap_Client
  290. * @throws Zend_Soap_Client_Exception with invalid soap version argument
  291. */
  292. public function setSoapVersion($version)
  293. {
  294. if (!in_array($version, array(SOAP_1_1, SOAP_1_2))) {
  295. require_once 'Zend/Soap/Client/Exception.php';
  296. throw new Zend_Soap_Client_Exception('Invalid soap version specified. Use SOAP_1_1 or SOAP_1_2 constants.');
  297. }
  298. $this->_soapVersion = $version;
  299. $this->_soapClient = null;
  300. return $this;
  301. }
  302. /**
  303. * Get SOAP version
  304. *
  305. * @return int
  306. */
  307. public function getSoapVersion()
  308. {
  309. return $this->_soapVersion;
  310. }
  311. /**
  312. * Set classmap
  313. *
  314. * @param array $classmap
  315. * @return Zend_Soap_Client
  316. * @throws Zend_Soap_Client_Exception for any invalid class in the class map
  317. */
  318. public function setClassmap(array $classmap)
  319. {
  320. foreach ($classmap as $type => $class) {
  321. if (!class_exists($class)) {
  322. require_once 'Zend/Soap/Client/Exception.php';
  323. throw new Zend_Soap_Client_Exception('Invalid class in class map');
  324. }
  325. }
  326. $this->_classmap = $classmap;
  327. $this->_soapClient = null;
  328. return $this;
  329. }
  330. /**
  331. * Retrieve classmap
  332. *
  333. * @return mixed
  334. */
  335. public function getClassmap()
  336. {
  337. return $this->_classmap;
  338. }
  339. /**
  340. * Set encoding
  341. *
  342. * @param string $encoding
  343. * @return Zend_Soap_Client
  344. * @throws Zend_Soap_Client_Exception with invalid encoding argument
  345. */
  346. public function setEncoding($encoding)
  347. {
  348. if (!is_string($encoding)) {
  349. require_once 'Zend/Soap/Client/Exception.php';
  350. throw new Zend_Soap_Client_Exception('Invalid encoding specified');
  351. }
  352. $this->_encoding = $encoding;
  353. $this->_soapClient = null;
  354. return $this;
  355. }
  356. /**
  357. * Get encoding
  358. *
  359. * @return string
  360. */
  361. public function getEncoding()
  362. {
  363. return $this->_encoding;
  364. }
  365. /**
  366. * Check for valid URN
  367. *
  368. * @param string $urn
  369. * @return true
  370. * @throws Zend_Soap_Client_Exception on invalid URN
  371. */
  372. public function validateUrn($urn)
  373. {
  374. $segs = parse_url($urn);
  375. if (isset($segs['scheme'])) {
  376. return true;
  377. }
  378. require_once 'Zend/Soap/Client/Exception.php';
  379. throw new Zend_Soap_Client_Exception('Invalid URN');
  380. }
  381. /**
  382. * Set URI
  383. *
  384. * URI in Web Service the target namespace
  385. *
  386. * @param string $uri
  387. * @return Zend_Soap_Client
  388. * @throws Zend_Soap_Client_Exception with invalid uri argument
  389. */
  390. public function setUri($uri)
  391. {
  392. $this->validateUrn($uri);
  393. $this->_uri = $uri;
  394. $this->_soapClient = null;
  395. return $this;
  396. }
  397. /**
  398. * Retrieve URI
  399. *
  400. * @return string
  401. */
  402. public function getUri()
  403. {
  404. return $this->_uri;
  405. }
  406. /**
  407. * Set Location
  408. *
  409. * URI in Web Service the target namespace
  410. *
  411. * @param string $location
  412. * @return Zend_Soap_Client
  413. * @throws Zend_Soap_Client_Exception with invalid uri argument
  414. */
  415. public function setLocation($location)
  416. {
  417. $this->validateUrn($location);
  418. $this->_location = $location;
  419. $this->_soapClient = null;
  420. return $this;
  421. }
  422. /**
  423. * Retrieve URI
  424. *
  425. * @return string
  426. */
  427. public function getLocation()
  428. {
  429. return $this->_location;
  430. }
  431. /**
  432. * Set request style
  433. *
  434. * @param int $style One of the SOAP_RPC or SOAP_DOCUMENT constants
  435. * @return Zend_Soap_Client
  436. * @throws Zend_Soap_Client_Exception with invalid style argument
  437. */
  438. public function setStyle($style)
  439. {
  440. if (!in_array($style, array(SOAP_RPC, SOAP_DOCUMENT))) {
  441. require_once 'Zend/Soap/Client/Exception.php';
  442. throw new Zend_Soap_Client_Exception('Invalid request style specified. Use SOAP_RPC or SOAP_DOCUMENT constants.');
  443. }
  444. $this->_style = $style;
  445. $this->_soapClient = null;
  446. return $this;
  447. }
  448. /**
  449. * Get request style
  450. *
  451. * @return int
  452. */
  453. public function getStyle()
  454. {
  455. return $this->_style;
  456. }
  457. /**
  458. * Set message encoding method
  459. *
  460. * @param int $use One of the SOAP_ENCODED or SOAP_LITERAL constants
  461. * @return Zend_Soap_Client
  462. * @throws Zend_Soap_Client_Exception with invalid message encoding method argument
  463. */
  464. public function setEncodingMethod($use)
  465. {
  466. if (!in_array($use, array(SOAP_ENCODED, SOAP_LITERAL))) {
  467. require_once 'Zend/Soap/Client/Exception.php';
  468. throw new Zend_Soap_Client_Exception('Invalid message encoding method. Use SOAP_ENCODED or SOAP_LITERAL constants.');
  469. }
  470. $this->_use = $use;
  471. $this->_soapClient = null;
  472. return $this;
  473. }
  474. /**
  475. * Get message encoding method
  476. *
  477. * @return int
  478. */
  479. public function getEncodingMethod()
  480. {
  481. return $this->_use;
  482. }
  483. /**
  484. * Set HTTP login
  485. *
  486. * @param string $login
  487. * @return Zend_Soap_Client
  488. */
  489. public function setHttpLogin($login)
  490. {
  491. $this->_login = $login;
  492. $this->_soapClient = null;
  493. return $this;
  494. }
  495. /**
  496. * Retrieve HTTP Login
  497. *
  498. * @return string
  499. */
  500. public function getHttpLogin()
  501. {
  502. return $this->_login;
  503. }
  504. /**
  505. * Set HTTP password
  506. *
  507. * @param string $password
  508. * @return Zend_Soap_Client
  509. */
  510. public function setHttpPassword($password)
  511. {
  512. $this->_password = $password;
  513. $this->_soapClient = null;
  514. return $this;
  515. }
  516. /**
  517. * Retrieve HTTP Password
  518. *
  519. * @return string
  520. */
  521. public function getHttpPassword()
  522. {
  523. return $this->_password;
  524. }
  525. /**
  526. * Set proxy host
  527. *
  528. * @param string $proxyHost
  529. * @return Zend_Soap_Client
  530. */
  531. public function setProxyHost($proxyHost)
  532. {
  533. $this->_proxy_host = $proxyHost;
  534. $this->_soapClient = null;
  535. return $this;
  536. }
  537. /**
  538. * Retrieve proxy host
  539. *
  540. * @return string
  541. */
  542. public function getProxyHost()
  543. {
  544. return $this->_proxy_host;
  545. }
  546. /**
  547. * Set proxy port
  548. *
  549. * @param int $proxyPort
  550. * @return Zend_Soap_Client
  551. */
  552. public function setProxyPort($proxyPort)
  553. {
  554. $this->_proxy_port = (int)$proxyPort;
  555. $this->_soapClient = null;
  556. return $this;
  557. }
  558. /**
  559. * Retrieve proxy port
  560. *
  561. * @return int
  562. */
  563. public function getProxyPort()
  564. {
  565. return $this->_proxy_port;
  566. }
  567. /**
  568. * Set proxy login
  569. *
  570. * @param string $proxyLogin
  571. * @return Zend_Soap_Client
  572. */
  573. public function setProxyLogin($proxyLogin)
  574. {
  575. $this->_proxy_login = $proxyLogin;
  576. $this->_soapClient = null;
  577. return $this;
  578. }
  579. /**
  580. * Retrieve proxy login
  581. *
  582. * @return string
  583. */
  584. public function getProxyLogin()
  585. {
  586. return $this->_proxy_login;
  587. }
  588. /**
  589. * Set proxy password
  590. *
  591. * @param string $proxyLogin
  592. * @return Zend_Soap_Client
  593. */
  594. public function setProxyPassword($proxyPassword)
  595. {
  596. $this->_proxy_password = $proxyPassword;
  597. $this->_soapClient = null;
  598. return $this;
  599. }
  600. /**
  601. * Set HTTPS client certificate path
  602. *
  603. * @param string $localCert local certificate path
  604. * @return Zend_Soap_Client
  605. * @throws Zend_Soap_Client_Exception with invalid local certificate path argument
  606. */
  607. public function setHttpsCertificate($localCert)
  608. {
  609. if (!is_readable($localCert)) {
  610. require_once 'Zend/Soap/Client/Exception.php';
  611. throw new Zend_Soap_Client_Exception('Invalid HTTPS client certificate path.');
  612. }
  613. $this->_local_cert = $localCert;
  614. $this->_soapClient = null;
  615. return $this;
  616. }
  617. /**
  618. * Get HTTPS client certificate path
  619. *
  620. * @return string
  621. */
  622. public function getHttpsCertificate()
  623. {
  624. return $this->_local_cert;
  625. }
  626. /**
  627. * Set HTTPS client certificate passphrase
  628. *
  629. * @param string $passphrase
  630. * @return Zend_Soap_Client
  631. */
  632. public function setHttpsCertPassphrase($passphrase)
  633. {
  634. $this->_passphrase = $passphrase;
  635. $this->_soapClient = null;
  636. return $this;
  637. }
  638. /**
  639. * Get HTTPS client certificate passphrase
  640. *
  641. * @return string
  642. */
  643. public function getHttpsCertPassphrase()
  644. {
  645. return $this->_passphrase;
  646. }
  647. /**
  648. * Set compression options
  649. *
  650. * @param int $compressionOptions
  651. * @return Zend_Soap_Client
  652. */
  653. public function setCompressionOptions($compressionOptions)
  654. {
  655. $this->_compression = $compressionOptions;
  656. $this->_soapClient = null;
  657. return $this;
  658. }
  659. /**
  660. * Get Compression options
  661. *
  662. * @return int
  663. */
  664. public function getCompressionOptions()
  665. {
  666. return $this->_compression;
  667. }
  668. /**
  669. * Retrieve proxy password
  670. *
  671. * @return string
  672. */
  673. public function getProxyPassword()
  674. {
  675. return $this->_proxy_password;
  676. }
  677. /**
  678. * Set Stream Context
  679. *
  680. * @return Zend_Soap_Client
  681. */
  682. public function setStreamContext($context)
  683. {
  684. if(!is_resource($context) || get_resource_type($context) !== "stream-context") {
  685. /**
  686. * @see Zend_Soap_Client_Exception
  687. */
  688. require_once "Zend/Soap/Client/Exception.php";
  689. throw new Zend_Soap_Client_Exception(
  690. "Invalid stream context resource given."
  691. );
  692. }
  693. $this->_stream_context = $context;
  694. return $this;
  695. }
  696. /**
  697. * Get Stream Context
  698. *
  699. * @return resource
  700. */
  701. public function getStreamContext()
  702. {
  703. return $this->_stream_context;
  704. }
  705. /**
  706. * Set the SOAP Feature options.
  707. *
  708. * @param string|int $feature
  709. * @return Zend_Soap_Client
  710. */
  711. public function setSoapFeatures($feature)
  712. {
  713. $this->_features = $feature;
  714. $this->_soapClient = null;
  715. return $this;
  716. }
  717. /**
  718. * Return current SOAP Features options
  719. *
  720. * @return int
  721. */
  722. public function getSoapFeatures()
  723. {
  724. return $this->_features;
  725. }
  726. /**
  727. * Set the SOAP Wsdl Caching Options
  728. *
  729. * @param string|int|boolean $caching
  730. * @return Zend_Soap_Client
  731. */
  732. public function setWsdlCache($options)
  733. {
  734. $this->_cache_wsdl = $options;
  735. return $this;
  736. }
  737. /**
  738. * Get current SOAP Wsdl Caching option
  739. */
  740. public function getWsdlCache()
  741. {
  742. return $this->_cache_wsdl;
  743. }
  744. /**
  745. * Retrieve request XML
  746. *
  747. * @return string
  748. */
  749. public function getLastRequest()
  750. {
  751. if ($this->_soapClient !== null) {
  752. return $this->_soapClient->__getLastRequest();
  753. }
  754. return '';
  755. }
  756. /**
  757. * Get response XML
  758. *
  759. * @return string
  760. */
  761. public function getLastResponse()
  762. {
  763. if ($this->_soapClient !== null) {
  764. return $this->_soapClient->__getLastResponse();
  765. }
  766. return '';
  767. }
  768. /**
  769. * Retrieve request headers
  770. *
  771. * @return string
  772. */
  773. public function getLastRequestHeaders()
  774. {
  775. if ($this->_soapClient !== null) {
  776. return $this->_soapClient->__getLastRequestHeaders();
  777. }
  778. return '';
  779. }
  780. /**
  781. * Retrieve response headers (as string)
  782. *
  783. * @return string
  784. */
  785. public function getLastResponseHeaders()
  786. {
  787. if ($this->_soapClient !== null) {
  788. return $this->_soapClient->__getLastResponseHeaders();
  789. }
  790. return '';
  791. }
  792. /**
  793. * Retrieve last invoked method
  794. *
  795. * @return string
  796. */
  797. public function getLastMethod()
  798. {
  799. return $this->_lastMethod;
  800. }
  801. /**
  802. * Do request proxy method.
  803. *
  804. * May be overridden in subclasses
  805. *
  806. * @internal
  807. * @param Zend_Soap_Client_Common $client
  808. * @param string $request
  809. * @param string $location
  810. * @param string $action
  811. * @param int $version
  812. * @param int $one_way
  813. * @return mixed
  814. */
  815. public function _doRequest(Zend_Soap_Client_Common $client, $request, $location, $action, $version, $one_way = null)
  816. {
  817. // Perform request as is
  818. if ($one_way == null) {
  819. return call_user_func(array($client,'SoapClient::__doRequest'), $request, $location, $action, $version);
  820. } else {
  821. return call_user_func(array($client,'SoapClient::__doRequest'), $request, $location, $action, $version, $one_way);
  822. }
  823. }
  824. /**
  825. * Initialize SOAP Client object
  826. *
  827. * @throws Zend_Soap_Client_Exception
  828. */
  829. protected function _initSoapClientObject()
  830. {
  831. $wsdl = $this->getWsdl();
  832. $options = array_merge($this->getOptions(), array('trace' => true));
  833. if ($wsdl == null) {
  834. if (!isset($options['location'])) {
  835. require_once 'Zend/Soap/Client/Exception.php';
  836. throw new Zend_Soap_Client_Exception('\'location\' parameter is required in non-WSDL mode.');
  837. }
  838. if (!isset($options['uri'])) {
  839. require_once 'Zend/Soap/Client/Exception.php';
  840. throw new Zend_Soap_Client_Exception('\'uri\' parameter is required in non-WSDL mode.');
  841. }
  842. } else {
  843. if (isset($options['use'])) {
  844. require_once 'Zend/Soap/Client/Exception.php';
  845. throw new Zend_Soap_Client_Exception('\'use\' parameter only works in non-WSDL mode.');
  846. }
  847. if (isset($options['style'])) {
  848. require_once 'Zend/Soap/Client/Exception.php';
  849. throw new Zend_Soap_Client_Exception('\'style\' parameter only works in non-WSDL mode.');
  850. }
  851. }
  852. unset($options['wsdl']);
  853. $this->_soapClient = new Zend_Soap_Client_Common(array($this, '_doRequest'), $wsdl, $options);
  854. }
  855. /**
  856. * Perform arguments pre-processing
  857. *
  858. * My be overridden in descendant classes
  859. *
  860. * @param array $arguments
  861. */
  862. protected function _preProcessArguments($arguments)
  863. {
  864. // Do nothing
  865. return $arguments;
  866. }
  867. /**
  868. * Perform result pre-processing
  869. *
  870. * My be overridden in descendant classes
  871. *
  872. * @param array $arguments
  873. */
  874. protected function _preProcessResult($result)
  875. {
  876. // Do nothing
  877. return $result;
  878. }
  879. /**
  880. * Add SOAP input header
  881. *
  882. * @param SoapHeader $header
  883. * @param boolean $permanent
  884. * @return Zend_Soap_Client
  885. */
  886. public function addSoapInputHeader(SoapHeader $header, $permanent = false)
  887. {
  888. if ($permanent) {
  889. $this->_permanentSoapInputHeaders[] = $header;
  890. } else {
  891. $this->_soapInputHeaders[] = $header;
  892. }
  893. return $this;
  894. }
  895. /**
  896. * Reset SOAP input headers
  897. *
  898. * @return Zend_Soap_Client
  899. */
  900. public function resetSoapInputHeaders()
  901. {
  902. $this->_permanentSoapInputHeaders = array();
  903. $this->_soapInputHeaders = array();
  904. return $this;
  905. }
  906. /**
  907. * Get last SOAP output headers
  908. *
  909. * @return array
  910. */
  911. public function getLastSoapOutputHeaderObjects()
  912. {
  913. return $this->_soapOutputHeaders;
  914. }
  915. /**
  916. * Perform a SOAP call
  917. *
  918. * @param string $name
  919. * @param array $arguments
  920. * @return mixed
  921. */
  922. public function __call($name, $arguments)
  923. {
  924. $soapClient = $this->getSoapClient();
  925. $this->_lastMethod = $name;
  926. $soapHeaders = array_merge($this->_permanentSoapInputHeaders, $this->_soapInputHeaders);
  927. $result = $soapClient->__soapCall($name,
  928. $this->_preProcessArguments($arguments),
  929. null, /* Options are already set to the SOAP client object */
  930. (count($soapHeaders) > 0)? $soapHeaders : null,
  931. $this->_soapOutputHeaders);
  932. // Reset non-permanent input headers
  933. $this->_soapInputHeaders = array();
  934. return $this->_preProcessResult($result);
  935. }
  936. /**
  937. * Return a list of available functions
  938. *
  939. * @return array
  940. * @throws Zend_Soap_Client_Exception
  941. */
  942. public function getFunctions()
  943. {
  944. if ($this->getWsdl() == null) {
  945. require_once 'Zend/Soap/Client/Exception.php';
  946. throw new Zend_Soap_Client_Exception('\'getFunctions\' method is available only in WSDL mode.');
  947. }
  948. $soapClient = $this->getSoapClient();
  949. return $soapClient->__getFunctions();
  950. }
  951. /**
  952. * Get used types.
  953. *
  954. * @return array
  955. */
  956. /**
  957. * Return a list of SOAP types
  958. *
  959. * @return array
  960. * @throws Zend_Soap_Client_Exception
  961. */
  962. public function getTypes()
  963. {
  964. if ($this->getWsdl() == null) {
  965. require_once 'Zend/Soap/Client/Exception.php';
  966. throw new Zend_Soap_Client_Exception('\'getTypes\' method is available only in WSDL mode.');
  967. }
  968. $soapClient = $this->getSoapClient();
  969. return $soapClient->__getTypes();
  970. }
  971. /**
  972. * @param SoapClient $soapClient
  973. * @return Zend_Soap_Client
  974. */
  975. public function setSoapClient(SoapClient $soapClient)
  976. {
  977. $this->_soapClient = $soapClient;
  978. return $this;
  979. }
  980. /**
  981. * @return SoapClient
  982. */
  983. public function getSoapClient()
  984. {
  985. if ($this->_soapClient == null) {
  986. $this->_initSoapClientObject();
  987. }
  988. return $this->_soapClient;
  989. }
  990. /**
  991. * @param string $name
  992. * @param string $value
  993. * @return Zend_Soap_Client
  994. */
  995. public function setCookie($cookieName, $cookieValue=null)
  996. {
  997. $soapClient = $this->getSoapClient();
  998. $soapClient->__setCookie($cookieName, $cookieValue);
  999. return $this;
  1000. }
  1001. }