Client.php 30 KB

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