Client.php 27 KB

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