Client.php 28 KB

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