Client.php 28 KB

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