Client.php 28 KB

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