Client.php 29 KB

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