PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/website/library/Zend/Soap/Server.php

https://bitbucket.org/efdac/e-forest_platform
PHP | 959 lines | 440 code | 102 blank | 417 comment | 57 complexity | 340e7ac40bf0e75416af3b0955ce86ff MD5 | raw file
  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 Server
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @see Zend_Server_Interface
  23. */
  24. require_once 'Zend/Server/Interface.php';
  25. /**
  26. * Zend_Soap_Server
  27. *
  28. * @category Zend
  29. * @package Zend_Soap
  30. * @subpackage Server
  31. * @uses Zend_Server_Interface
  32. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. * @version $Id: Server.php 20096 2010-01-06 02:05:09Z bkarwin $
  35. */
  36. class Zend_Soap_Server implements Zend_Server_Interface
  37. {
  38. /**
  39. * Actor URI
  40. * @var string URI
  41. */
  42. protected $_actor;
  43. /**
  44. * Class registered with this server
  45. * @var string
  46. */
  47. protected $_class;
  48. /**
  49. * Arguments to pass to {@link $_class} constructor
  50. * @var array
  51. */
  52. protected $_classArgs = array();
  53. /**
  54. * Object registered with this server
  55. */
  56. protected $_object;
  57. /**
  58. * Array of SOAP type => PHP class pairings for handling return/incoming values
  59. * @var array
  60. */
  61. protected $_classmap;
  62. /**
  63. * Encoding
  64. * @var string
  65. */
  66. protected $_encoding;
  67. /**
  68. * SOAP Server Features
  69. *
  70. * @var int
  71. */
  72. protected $_features;
  73. /**
  74. * WSDL Caching Options of SOAP Server
  75. *
  76. * @var mixed
  77. */
  78. protected $_wsdlCache;
  79. /**
  80. * Registered fault exceptions
  81. * @var array
  82. */
  83. protected $_faultExceptions = array();
  84. /**
  85. * Functions registered with this server; may be either an array or the SOAP_FUNCTIONS_ALL
  86. * constant
  87. * @var array|int
  88. */
  89. protected $_functions = array();
  90. /**
  91. * Persistence mode; should be one of the SOAP persistence constants
  92. * @var int
  93. */
  94. protected $_persistence;
  95. /**
  96. * Request XML
  97. * @var string
  98. */
  99. protected $_request;
  100. /**
  101. * Response XML
  102. * @var string
  103. */
  104. protected $_response;
  105. /**
  106. * Flag: whether or not {@link handle()} should return a response instead
  107. * of automatically emitting it.
  108. * @var boolean
  109. */
  110. protected $_returnResponse = false;
  111. /**
  112. * SOAP version to use; SOAP_1_2 by default, to allow processing of headers
  113. * @var int
  114. */
  115. protected $_soapVersion = SOAP_1_2;
  116. /**
  117. * URI or path to WSDL
  118. * @var string
  119. */
  120. protected $_wsdl;
  121. /**
  122. * URI namespace for SOAP server
  123. * @var string URI
  124. */
  125. protected $_uri;
  126. /**
  127. * Constructor
  128. *
  129. * Sets display_errors INI setting to off (prevent client errors due to bad
  130. * XML in response). Registers {@link handlePhpErrors()} as error handler
  131. * for E_USER_ERROR.
  132. *
  133. * If $wsdl is provided, it is passed on to {@link setWsdl()}; if any
  134. * options are specified, they are passed on to {@link setOptions()}.
  135. *
  136. * @param string $wsdl
  137. * @param array $options
  138. * @return void
  139. */
  140. public function __construct($wsdl = null, array $options = null)
  141. {
  142. if (!extension_loaded('soap')) {
  143. require_once 'Zend/Soap/Server/Exception.php';
  144. throw new Zend_Soap_Server_Exception('SOAP extension is not loaded.');
  145. }
  146. if (null !== $wsdl) {
  147. $this->setWsdl($wsdl);
  148. }
  149. if (null !== $options) {
  150. $this->setOptions($options);
  151. }
  152. }
  153. /**
  154. * Set Options
  155. *
  156. * Allows setting options as an associative array of option => value pairs.
  157. *
  158. * @param array|Zend_Config $options
  159. * @return Zend_Soap_Server
  160. */
  161. public function setOptions($options)
  162. {
  163. if($options instanceof Zend_Config) {
  164. $options = $options->toArray();
  165. }
  166. foreach ($options as $key => $value) {
  167. switch ($key) {
  168. case 'actor':
  169. $this->setActor($value);
  170. break;
  171. case 'classmap':
  172. case 'classMap':
  173. $this->setClassmap($value);
  174. break;
  175. case 'encoding':
  176. $this->setEncoding($value);
  177. break;
  178. case 'soapVersion':
  179. case 'soap_version':
  180. $this->setSoapVersion($value);
  181. break;
  182. case 'uri':
  183. $this->setUri($value);
  184. break;
  185. case 'wsdl':
  186. $this->setWsdl($value);
  187. break;
  188. case 'featues':
  189. $this->setSoapFeatures($value);
  190. break;
  191. case 'cache_wsdl':
  192. $this->setWsdlCache($value);
  193. break;
  194. default:
  195. break;
  196. }
  197. }
  198. return $this;
  199. }
  200. /**
  201. * Return array of options suitable for using with SoapServer constructor
  202. *
  203. * @return array
  204. */
  205. public function getOptions()
  206. {
  207. $options = array();
  208. if (null !== $this->_actor) {
  209. $options['actor'] = $this->_actor;
  210. }
  211. if (null !== $this->_classmap) {
  212. $options['classmap'] = $this->_classmap;
  213. }
  214. if (null !== $this->_encoding) {
  215. $options['encoding'] = $this->_encoding;
  216. }
  217. if (null !== $this->_soapVersion) {
  218. $options['soap_version'] = $this->_soapVersion;
  219. }
  220. if (null !== $this->_uri) {
  221. $options['uri'] = $this->_uri;
  222. }
  223. if(null !== $this->_features) {
  224. $options['features'] = $this->_features;
  225. }
  226. if(null !== $this->_wsdlCache) {
  227. $options['cache_wsdl'] = $this->_wsdlCache;
  228. }
  229. return $options;
  230. }
  231. /**
  232. * Set encoding
  233. *
  234. * @param string $encoding
  235. * @return Zend_Soap_Server
  236. * @throws Zend_Soap_Server_Exception with invalid encoding argument
  237. */
  238. public function setEncoding($encoding)
  239. {
  240. if (!is_string($encoding)) {
  241. require_once 'Zend/Soap/Server/Exception.php';
  242. throw new Zend_Soap_Server_Exception('Invalid encoding specified');
  243. }
  244. $this->_encoding = $encoding;
  245. return $this;
  246. }
  247. /**
  248. * Get encoding
  249. *
  250. * @return string
  251. */
  252. public function getEncoding()
  253. {
  254. return $this->_encoding;
  255. }
  256. /**
  257. * Set SOAP version
  258. *
  259. * @param int $version One of the SOAP_1_1 or SOAP_1_2 constants
  260. * @return Zend_Soap_Server
  261. * @throws Zend_Soap_Server_Exception with invalid soap version argument
  262. */
  263. public function setSoapVersion($version)
  264. {
  265. if (!in_array($version, array(SOAP_1_1, SOAP_1_2))) {
  266. require_once 'Zend/Soap/Server/Exception.php';
  267. throw new Zend_Soap_Server_Exception('Invalid soap version specified');
  268. }
  269. $this->_soapVersion = $version;
  270. return $this;
  271. }
  272. /**
  273. * Get SOAP version
  274. *
  275. * @return int
  276. */
  277. public function getSoapVersion()
  278. {
  279. return $this->_soapVersion;
  280. }
  281. /**
  282. * Check for valid URN
  283. *
  284. * @param string $urn
  285. * @return true
  286. * @throws Zend_Soap_Server_Exception on invalid URN
  287. */
  288. public function validateUrn($urn)
  289. {
  290. $scheme = parse_url($urn, PHP_URL_SCHEME);
  291. if ($scheme === false || $scheme === null) {
  292. require_once 'Zend/Soap/Server/Exception.php';
  293. throw new Zend_Soap_Server_Exception('Invalid URN');
  294. }
  295. return true;
  296. }
  297. /**
  298. * Set actor
  299. *
  300. * Actor is the actor URI for the server.
  301. *
  302. * @param string $actor
  303. * @return Zend_Soap_Server
  304. */
  305. public function setActor($actor)
  306. {
  307. $this->validateUrn($actor);
  308. $this->_actor = $actor;
  309. return $this;
  310. }
  311. /**
  312. * Retrieve actor
  313. *
  314. * @return string
  315. */
  316. public function getActor()
  317. {
  318. return $this->_actor;
  319. }
  320. /**
  321. * Set URI
  322. *
  323. * URI in SoapServer is actually the target namespace, not a URI; $uri must begin with 'urn:'.
  324. *
  325. * @param string $uri
  326. * @return Zend_Soap_Server
  327. * @throws Zend_Soap_Server_Exception with invalid uri argument
  328. */
  329. public function setUri($uri)
  330. {
  331. $this->validateUrn($uri);
  332. $this->_uri = $uri;
  333. return $this;
  334. }
  335. /**
  336. * Retrieve URI
  337. *
  338. * @return string
  339. */
  340. public function getUri()
  341. {
  342. return $this->_uri;
  343. }
  344. /**
  345. * Set classmap
  346. *
  347. * @param array $classmap
  348. * @return Zend_Soap_Server
  349. * @throws Zend_Soap_Server_Exception for any invalid class in the class map
  350. */
  351. public function setClassmap($classmap)
  352. {
  353. if (!is_array($classmap)) {
  354. /**
  355. * @see Zend_Soap_Server_Exception
  356. */
  357. require_once 'Zend/Soap/Server/Exception.php';
  358. throw new Zend_Soap_Server_Exception('Classmap must be an array');
  359. }
  360. foreach ($classmap as $type => $class) {
  361. if (!class_exists($class)) {
  362. /**
  363. * @see Zend_Soap_Server_Exception
  364. */
  365. require_once 'Zend/Soap/Server/Exception.php';
  366. throw new Zend_Soap_Server_Exception('Invalid class in class map');
  367. }
  368. }
  369. $this->_classmap = $classmap;
  370. return $this;
  371. }
  372. /**
  373. * Retrieve classmap
  374. *
  375. * @return mixed
  376. */
  377. public function getClassmap()
  378. {
  379. return $this->_classmap;
  380. }
  381. /**
  382. * Set wsdl
  383. *
  384. * @param string $wsdl URI or path to a WSDL
  385. * @return Zend_Soap_Server
  386. */
  387. public function setWsdl($wsdl)
  388. {
  389. $this->_wsdl = $wsdl;
  390. return $this;
  391. }
  392. /**
  393. * Retrieve wsdl
  394. *
  395. * @return string
  396. */
  397. public function getWsdl()
  398. {
  399. return $this->_wsdl;
  400. }
  401. /**
  402. * Set the SOAP Feature options.
  403. *
  404. * @param string|int $feature
  405. * @return Zend_Soap_Server
  406. */
  407. public function setSoapFeatures($feature)
  408. {
  409. $this->_features = $feature;
  410. return $this;
  411. }
  412. /**
  413. * Return current SOAP Features options
  414. *
  415. * @return int
  416. */
  417. public function getSoapFeatures()
  418. {
  419. return $this->_features;
  420. }
  421. /**
  422. * Set the SOAP Wsdl Caching Options
  423. *
  424. * @param string|int|boolean $caching
  425. * @return Zend_Soap_Server
  426. */
  427. public function setWsdlCache($options)
  428. {
  429. $this->_wsdlCache = $options;
  430. return $this;
  431. }
  432. /**
  433. * Get current SOAP Wsdl Caching option
  434. */
  435. public function getWsdlCache()
  436. {
  437. return $this->_wsdlCache;
  438. }
  439. /**
  440. * Attach a function as a server method
  441. *
  442. * @param array|string $function Function name, array of function names to attach,
  443. * or SOAP_FUNCTIONS_ALL to attach all functions
  444. * @param string $namespace Ignored
  445. * @return Zend_Soap_Server
  446. * @throws Zend_Soap_Server_Exception on invalid functions
  447. */
  448. public function addFunction($function, $namespace = '')
  449. {
  450. // Bail early if set to SOAP_FUNCTIONS_ALL
  451. if ($this->_functions == SOAP_FUNCTIONS_ALL) {
  452. return $this;
  453. }
  454. if (is_array($function)) {
  455. foreach ($function as $func) {
  456. if (is_string($func) && function_exists($func)) {
  457. $this->_functions[] = $func;
  458. } else {
  459. require_once 'Zend/Soap/Server/Exception.php';
  460. throw new Zend_Soap_Server_Exception('One or more invalid functions specified in array');
  461. }
  462. }
  463. $this->_functions = array_merge($this->_functions, $function);
  464. } elseif (is_string($function) && function_exists($function)) {
  465. $this->_functions[] = $function;
  466. } elseif ($function == SOAP_FUNCTIONS_ALL) {
  467. $this->_functions = SOAP_FUNCTIONS_ALL;
  468. } else {
  469. require_once 'Zend/Soap/Server/Exception.php';
  470. throw new Zend_Soap_Server_Exception('Invalid function specified');
  471. }
  472. if (is_array($this->_functions)) {
  473. $this->_functions = array_unique($this->_functions);
  474. }
  475. return $this;
  476. }
  477. /**
  478. * Attach a class to a server
  479. *
  480. * Accepts a class name to use when handling requests. Any additional
  481. * arguments will be passed to that class' constructor when instantiated.
  482. *
  483. * See {@link setObject()} to set preconfigured object instances as request handlers.
  484. *
  485. * @param string $class Class Name which executes SOAP Requests at endpoint.
  486. * @return Zend_Soap_Server
  487. * @throws Zend_Soap_Server_Exception if called more than once, or if class
  488. * does not exist
  489. */
  490. public function setClass($class, $namespace = '', $argv = null)
  491. {
  492. if (isset($this->_class)) {
  493. require_once 'Zend/Soap/Server/Exception.php';
  494. throw new Zend_Soap_Server_Exception('A class has already been registered with this soap server instance');
  495. }
  496. if (!is_string($class)) {
  497. require_once 'Zend/Soap/Server/Exception.php';
  498. throw new Zend_Soap_Server_Exception('Invalid class argument (' . gettype($class) . ')');
  499. }
  500. if (!class_exists($class)) {
  501. require_once 'Zend/Soap/Server/Exception.php';
  502. throw new Zend_Soap_Server_Exception('Class "' . $class . '" does not exist');
  503. }
  504. $this->_class = $class;
  505. if (1 < func_num_args()) {
  506. $argv = func_get_args();
  507. array_shift($argv);
  508. $this->_classArgs = $argv;
  509. }
  510. return $this;
  511. }
  512. /**
  513. * Attach an object to a server
  514. *
  515. * Accepts an instanciated object to use when handling requests.
  516. *
  517. * @param object $object
  518. * @return Zend_Soap_Server
  519. */
  520. public function setObject($object)
  521. {
  522. if(!is_object($object)) {
  523. require_once 'Zend/Soap/Server/Exception.php';
  524. throw new Zend_Soap_Server_Exception('Invalid object argument ('.gettype($object).')');
  525. }
  526. if(isset($this->_object)) {
  527. require_once 'Zend/Soap/Server/Exception.php';
  528. throw new Zend_Soap_Server_Exception('An object has already been registered with this soap server instance');
  529. }
  530. $this->_object = $object;
  531. return $this;
  532. }
  533. /**
  534. * Return a server definition array
  535. *
  536. * Returns a list of all functions registered with {@link addFunction()},
  537. * merged with all public methods of the class set with {@link setClass()}
  538. * (if any).
  539. *
  540. * @access public
  541. * @return array
  542. */
  543. public function getFunctions()
  544. {
  545. $functions = array();
  546. if (null !== $this->_class) {
  547. $functions = get_class_methods($this->_class);
  548. } elseif (null !== $this->_object) {
  549. $functions = get_class_methods($this->_object);
  550. }
  551. return array_merge((array) $this->_functions, $functions);
  552. }
  553. /**
  554. * Unimplemented: Load server definition
  555. *
  556. * @param array $array
  557. * @return void
  558. * @throws Zend_Soap_Server_Exception Unimplemented
  559. */
  560. public function loadFunctions($definition)
  561. {
  562. require_once 'Zend/Soap/Server/Exception.php';
  563. throw new Zend_Soap_Server_Exception('Unimplemented');
  564. }
  565. /**
  566. * Set server persistence
  567. *
  568. * @param int $mode
  569. * @return Zend_Soap_Server
  570. */
  571. public function setPersistence($mode)
  572. {
  573. if (!in_array($mode, array(SOAP_PERSISTENCE_SESSION, SOAP_PERSISTENCE_REQUEST))) {
  574. require_once 'Zend/Soap/Server/Exception.php';
  575. throw new Zend_Soap_Server_Exception('Invalid persistence mode specified');
  576. }
  577. $this->_persistence = $mode;
  578. return $this;
  579. }
  580. /**
  581. * Get server persistence
  582. *
  583. * @return Zend_Soap_Server
  584. */
  585. public function getPersistence()
  586. {
  587. return $this->_persistence;
  588. }
  589. /**
  590. * Set request
  591. *
  592. * $request may be any of:
  593. * - DOMDocument; if so, then cast to XML
  594. * - DOMNode; if so, then grab owner document and cast to XML
  595. * - SimpleXMLElement; if so, then cast to XML
  596. * - stdClass; if so, calls __toString() and verifies XML
  597. * - string; if so, verifies XML
  598. *
  599. * @param DOMDocument|DOMNode|SimpleXMLElement|stdClass|string $request
  600. * @return Zend_Soap_Server
  601. */
  602. protected function _setRequest($request)
  603. {
  604. if ($request instanceof DOMDocument) {
  605. $xml = $request->saveXML();
  606. } elseif ($request instanceof DOMNode) {
  607. $xml = $request->ownerDocument->saveXML();
  608. } elseif ($request instanceof SimpleXMLElement) {
  609. $xml = $request->asXML();
  610. } elseif (is_object($request) || is_string($request)) {
  611. if (is_object($request)) {
  612. $xml = $request->__toString();
  613. } else {
  614. $xml = $request;
  615. }
  616. $dom = new DOMDocument();
  617. if(strlen($xml) == 0 || !$dom->loadXML($xml)) {
  618. require_once 'Zend/Soap/Server/Exception.php';
  619. throw new Zend_Soap_Server_Exception('Invalid XML');
  620. }
  621. }
  622. $this->_request = $xml;
  623. return $this;
  624. }
  625. /**
  626. * Retrieve request XML
  627. *
  628. * @return string
  629. */
  630. public function getLastRequest()
  631. {
  632. return $this->_request;
  633. }
  634. /**
  635. * Set return response flag
  636. *
  637. * If true, {@link handle()} will return the response instead of
  638. * automatically sending it back to the requesting client.
  639. *
  640. * The response is always available via {@link getResponse()}.
  641. *
  642. * @param boolean $flag
  643. * @return Zend_Soap_Server
  644. */
  645. public function setReturnResponse($flag)
  646. {
  647. $this->_returnResponse = ($flag) ? true : false;
  648. return $this;
  649. }
  650. /**
  651. * Retrieve return response flag
  652. *
  653. * @return boolean
  654. */
  655. public function getReturnResponse()
  656. {
  657. return $this->_returnResponse;
  658. }
  659. /**
  660. * Get response XML
  661. *
  662. * @return string
  663. */
  664. public function getLastResponse()
  665. {
  666. return $this->_response;
  667. }
  668. /**
  669. * Get SoapServer object
  670. *
  671. * Uses {@link $_wsdl} and return value of {@link getOptions()} to instantiate
  672. * SoapServer object, and then registers any functions or class with it, as
  673. * well as peristence.
  674. *
  675. * @return SoapServer
  676. */
  677. protected function _getSoap()
  678. {
  679. $options = $this->getOptions();
  680. $server = new SoapServer($this->_wsdl, $options);
  681. if (!empty($this->_functions)) {
  682. $server->addFunction($this->_functions);
  683. }
  684. if (!empty($this->_class)) {
  685. $args = $this->_classArgs;
  686. array_unshift($args, $this->_class);
  687. call_user_func_array(array($server, 'setClass'), $args);
  688. }
  689. if (!empty($this->_object)) {
  690. $server->setObject($this->_object);
  691. }
  692. if (null !== $this->_persistence) {
  693. $server->setPersistence($this->_persistence);
  694. }
  695. return $server;
  696. }
  697. /**
  698. * Handle a request
  699. *
  700. * Instantiates SoapServer object with options set in object, and
  701. * dispatches its handle() method.
  702. *
  703. * $request may be any of:
  704. * - DOMDocument; if so, then cast to XML
  705. * - DOMNode; if so, then grab owner document and cast to XML
  706. * - SimpleXMLElement; if so, then cast to XML
  707. * - stdClass; if so, calls __toString() and verifies XML
  708. * - string; if so, verifies XML
  709. *
  710. * If no request is passed, pulls request using php:://input (for
  711. * cross-platform compatability purposes).
  712. *
  713. * @param DOMDocument|DOMNode|SimpleXMLElement|stdClass|string $request Optional request
  714. * @return void|string
  715. */
  716. public function handle($request = null)
  717. {
  718. if (null === $request) {
  719. $request = file_get_contents('php://input');
  720. }
  721. // Set Zend_Soap_Server error handler
  722. $displayErrorsOriginalState = $this->_initializeSoapErrorContext();
  723. $setRequestException = null;
  724. /**
  725. * @see Zend_Soap_Server_Exception
  726. */
  727. require_once 'Zend/Soap/Server/Exception.php';
  728. try {
  729. $this->_setRequest($request);
  730. } catch (Zend_Soap_Server_Exception $e) {
  731. $setRequestException = $e;
  732. }
  733. $soap = $this->_getSoap();
  734. ob_start();
  735. if($setRequestException instanceof Exception) {
  736. // Send SOAP fault message if we've catched exception
  737. $soap->fault("Sender", $setRequestException->getMessage());
  738. } else {
  739. try {
  740. $soap->handle($request);
  741. } catch (Exception $e) {
  742. $fault = $this->fault($e);
  743. $soap->fault($fault->faultcode, $fault->faultstring);
  744. }
  745. }
  746. $this->_response = ob_get_clean();
  747. // Restore original error handler
  748. restore_error_handler();
  749. ini_set('display_errors', $displayErrorsOriginalState);
  750. if (!$this->_returnResponse) {
  751. echo $this->_response;
  752. return;
  753. }
  754. return $this->_response;
  755. }
  756. /**
  757. * Method initalizes the error context that the SOAPServer enviroment will run in.
  758. *
  759. * @return boolean display_errors original value
  760. */
  761. protected function _initializeSoapErrorContext()
  762. {
  763. $displayErrorsOriginalState = ini_get('display_errors');
  764. ini_set('display_errors', false);
  765. set_error_handler(array($this, 'handlePhpErrors'), E_USER_ERROR);
  766. return $displayErrorsOriginalState;
  767. }
  768. /**
  769. * Register a valid fault exception
  770. *
  771. * @param string|array $class Exception class or array of exception classes
  772. * @return Zend_Soap_Server
  773. */
  774. public function registerFaultException($class)
  775. {
  776. $this->_faultExceptions = array_merge($this->_faultExceptions, (array) $class);
  777. return $this;
  778. }
  779. /**
  780. * Deregister a fault exception from the fault exception stack
  781. *
  782. * @param string $class
  783. * @return boolean
  784. */
  785. public function deregisterFaultException($class)
  786. {
  787. if (in_array($class, $this->_faultExceptions, true)) {
  788. $index = array_search($class, $this->_faultExceptions);
  789. unset($this->_faultExceptions[$index]);
  790. return true;
  791. }
  792. return false;
  793. }
  794. /**
  795. * Return fault exceptions list
  796. *
  797. * @return array
  798. */
  799. public function getFaultExceptions()
  800. {
  801. return $this->_faultExceptions;
  802. }
  803. /**
  804. * Generate a server fault
  805. *
  806. * Note that the arguments are reverse to those of SoapFault.
  807. *
  808. * If an exception is passed as the first argument, its message and code
  809. * will be used to create the fault object if it has been registered via
  810. * {@Link registerFaultException()}.
  811. *
  812. * @link http://www.w3.org/TR/soap12-part1/#faultcodes
  813. * @param string|Exception $fault
  814. * @param string $code SOAP Fault Codes
  815. * @return SoapFault
  816. */
  817. public function fault($fault = null, $code = "Receiver")
  818. {
  819. if ($fault instanceof Exception) {
  820. $class = get_class($fault);
  821. if (in_array($class, $this->_faultExceptions)) {
  822. $message = $fault->getMessage();
  823. $eCode = $fault->getCode();
  824. $code = empty($eCode) ? $code : $eCode;
  825. } else {
  826. $message = 'Unknown error';
  827. }
  828. } elseif(is_string($fault)) {
  829. $message = $fault;
  830. } else {
  831. $message = 'Unknown error';
  832. }
  833. $allowedFaultModes = array(
  834. 'VersionMismatch', 'MustUnderstand', 'DataEncodingUnknown',
  835. 'Sender', 'Receiver', 'Server'
  836. );
  837. if(!in_array($code, $allowedFaultModes)) {
  838. $code = "Receiver";
  839. }
  840. return new SoapFault($code, $message);
  841. }
  842. /**
  843. * Throw PHP errors as SoapFaults
  844. *
  845. * @param int $errno
  846. * @param string $errstr
  847. * @param string $errfile
  848. * @param int $errline
  849. * @param array $errcontext
  850. * @return void
  851. * @throws SoapFault
  852. */
  853. public function handlePhpErrors($errno, $errstr, $errfile = null, $errline = null, array $errcontext = null)
  854. {
  855. throw $this->fault($errstr, "Receiver");
  856. }
  857. }