Client.php 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117
  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. return $this;
  715. }
  716. /**
  717. * Return current SOAP Features options
  718. *
  719. * @return int
  720. */
  721. public function getSoapFeatures()
  722. {
  723. return $this->_features;
  724. }
  725. /**
  726. * Set the SOAP Wsdl Caching Options
  727. *
  728. * @param string|int|boolean $caching
  729. * @return Zend_Soap_Client
  730. */
  731. public function setWsdlCache($options)
  732. {
  733. $this->_cache_wsdl = $options;
  734. return $this;
  735. }
  736. /**
  737. * Get current SOAP Wsdl Caching option
  738. */
  739. public function getWsdlCache()
  740. {
  741. return $this->_cache_wsdl;
  742. }
  743. /**
  744. * Retrieve request XML
  745. *
  746. * @return string
  747. */
  748. public function getLastRequest()
  749. {
  750. if ($this->_soapClient !== null) {
  751. return $this->_soapClient->__getLastRequest();
  752. }
  753. return '';
  754. }
  755. /**
  756. * Get response XML
  757. *
  758. * @return string
  759. */
  760. public function getLastResponse()
  761. {
  762. if ($this->_soapClient !== null) {
  763. return $this->_soapClient->__getLastResponse();
  764. }
  765. return '';
  766. }
  767. /**
  768. * Retrieve request headers
  769. *
  770. * @return string
  771. */
  772. public function getLastRequestHeaders()
  773. {
  774. if ($this->_soapClient !== null) {
  775. return $this->_soapClient->__getLastRequestHeaders();
  776. }
  777. return '';
  778. }
  779. /**
  780. * Retrieve response headers (as string)
  781. *
  782. * @return string
  783. */
  784. public function getLastResponseHeaders()
  785. {
  786. if ($this->_soapClient !== null) {
  787. return $this->_soapClient->__getLastResponseHeaders();
  788. }
  789. return '';
  790. }
  791. /**
  792. * Retrieve last invoked method
  793. *
  794. * @return string
  795. */
  796. public function getLastMethod()
  797. {
  798. return $this->_lastMethod;
  799. }
  800. /**
  801. * Do request proxy method.
  802. *
  803. * May be overridden in subclasses
  804. *
  805. * @internal
  806. * @param Zend_Soap_Client_Common $client
  807. * @param string $request
  808. * @param string $location
  809. * @param string $action
  810. * @param int $version
  811. * @param int $one_way
  812. * @return mixed
  813. */
  814. public function _doRequest(Zend_Soap_Client_Common $client, $request, $location, $action, $version, $one_way = null)
  815. {
  816. // Perform request as is
  817. if ($one_way == null) {
  818. return call_user_func(array($client,'SoapClient::__doRequest'), $request, $location, $action, $version);
  819. } else {
  820. return call_user_func(array($client,'SoapClient::__doRequest'), $request, $location, $action, $version, $one_way);
  821. }
  822. }
  823. /**
  824. * Initialize SOAP Client object
  825. *
  826. * @throws Zend_Soap_Client_Exception
  827. */
  828. protected function _initSoapClientObject()
  829. {
  830. $wsdl = $this->getWsdl();
  831. $options = array_merge($this->getOptions(), array('trace' => true));
  832. if ($wsdl == null) {
  833. if (!isset($options['location'])) {
  834. require_once 'Zend/Soap/Client/Exception.php';
  835. throw new Zend_Soap_Client_Exception('\'location\' parameter is required in non-WSDL mode.');
  836. }
  837. if (!isset($options['uri'])) {
  838. require_once 'Zend/Soap/Client/Exception.php';
  839. throw new Zend_Soap_Client_Exception('\'uri\' parameter is required in non-WSDL mode.');
  840. }
  841. } else {
  842. if (isset($options['use'])) {
  843. require_once 'Zend/Soap/Client/Exception.php';
  844. throw new Zend_Soap_Client_Exception('\'use\' parameter only works in non-WSDL mode.');
  845. }
  846. if (isset($options['style'])) {
  847. require_once 'Zend/Soap/Client/Exception.php';
  848. throw new Zend_Soap_Client_Exception('\'style\' parameter only works in non-WSDL mode.');
  849. }
  850. }
  851. unset($options['wsdl']);
  852. $this->_soapClient = new Zend_Soap_Client_Common(array($this, '_doRequest'), $wsdl, $options);
  853. }
  854. /**
  855. * Perform arguments pre-processing
  856. *
  857. * My be overridden in descendant classes
  858. *
  859. * @param array $arguments
  860. */
  861. protected function _preProcessArguments($arguments)
  862. {
  863. // Do nothing
  864. return $arguments;
  865. }
  866. /**
  867. * Perform result pre-processing
  868. *
  869. * My be overridden in descendant classes
  870. *
  871. * @param array $arguments
  872. */
  873. protected function _preProcessResult($result)
  874. {
  875. // Do nothing
  876. return $result;
  877. }
  878. /**
  879. * Add SOAP input header
  880. *
  881. * @param SoapHeader $header
  882. * @param boolean $permanent
  883. * @return Zend_Soap_Client
  884. */
  885. public function addSoapInputHeader(SoapHeader $header, $permanent = false)
  886. {
  887. if ($permanent) {
  888. $this->_permanentSoapInputHeaders[] = $header;
  889. } else {
  890. $this->_soapInputHeaders[] = $header;
  891. }
  892. return $this;
  893. }
  894. /**
  895. * Reset SOAP input headers
  896. *
  897. * @return Zend_Soap_Client
  898. */
  899. public function resetSoapInputHeaders()
  900. {
  901. $this->_permanentSoapInputHeaders = array();
  902. $this->_soapInputHeaders = array();
  903. return $this;
  904. }
  905. /**
  906. * Get last SOAP output headers
  907. *
  908. * @return array
  909. */
  910. public function getLastSoapOutputHeaderObjects()
  911. {
  912. return $this->_soapOutputHeaders;
  913. }
  914. /**
  915. * Perform a SOAP call
  916. *
  917. * @param string $name
  918. * @param array $arguments
  919. * @return mixed
  920. */
  921. public function __call($name, $arguments)
  922. {
  923. if ($this->_soapClient == null) {
  924. $this->_initSoapClientObject();
  925. }
  926. $this->_lastMethod = $name;
  927. $soapHeaders = array_merge($this->_permanentSoapInputHeaders, $this->_soapInputHeaders);
  928. $result = $this->_soapClient->__soapCall($name,
  929. $this->_preProcessArguments($arguments),
  930. null, /* Options are already set to the SOAP client object */
  931. (count($soapHeaders) > 0)? $soapHeaders : null,
  932. $this->_soapOutputHeaders);
  933. // Reset non-permanent input headers
  934. $this->_soapInputHeaders = array();
  935. return $this->_preProcessResult($result);
  936. }
  937. /**
  938. * Return a list of available functions
  939. *
  940. * @return array
  941. * @throws Zend_Soap_Client_Exception
  942. */
  943. public function getFunctions()
  944. {
  945. if ($this->getWsdl() == null) {
  946. require_once 'Zend/Soap/Client/Exception.php';
  947. throw new Zend_Soap_Client_Exception('\'getFunctions\' method is available only in WSDL mode.');
  948. }
  949. if ($this->_soapClient == null) {
  950. $this->_initSoapClientObject();
  951. }
  952. return $this->_soapClient->__getFunctions();
  953. }
  954. /**
  955. * Get used types.
  956. *
  957. * @return array
  958. */
  959. /**
  960. * Return a list of SOAP types
  961. *
  962. * @return array
  963. * @throws Zend_Soap_Client_Exception
  964. */
  965. public function getTypes()
  966. {
  967. if ($this->getWsdl() == null) {
  968. require_once 'Zend/Soap/Client/Exception.php';
  969. throw new Zend_Soap_Client_Exception('\'getTypes\' method is available only in WSDL mode.');
  970. }
  971. if ($this->_soapClient == null) {
  972. $this->_initSoapClientObject();
  973. }
  974. return $this->_soapClient->__getTypes();
  975. }
  976. }