import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
@ -14,25 +14,26 @@
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Soap
|
||||
* @subpackage Server
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Server_Interface */
|
||||
/**
|
||||
* @see Zend_Server_Interface
|
||||
*/
|
||||
require_once 'Zend/Server/Interface.php';
|
||||
|
||||
/** Zend_Soap_Server_Exception */
|
||||
require_once 'Zend/Soap/Server/Exception.php';
|
||||
|
||||
/**
|
||||
* Zend_Soap_Server
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Soap
|
||||
* @subpackage Server
|
||||
* @uses Zend_Server_Interface
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Server.php 12627 2008-11-13 17:04:56Z alexander $
|
||||
* @version $Id: Server.php 14918 2009-04-15 16:07:53Z beberlei $
|
||||
*/
|
||||
class Zend_Soap_Server implements Zend_Server_Interface
|
||||
{
|
||||
@ -71,6 +72,21 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
*/
|
||||
protected $_encoding;
|
||||
|
||||
/**
|
||||
* SOAP Server Features
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_features;
|
||||
|
||||
/**
|
||||
* WSDL Caching Options of SOAP Server
|
||||
*
|
||||
* @var
|
||||
*/
|
||||
protected $_wsdlCache;
|
||||
|
||||
|
||||
/**
|
||||
* Registered fault exceptions
|
||||
* @var array
|
||||
@ -144,6 +160,7 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
public function __construct($wsdl = null, array $options = null)
|
||||
{
|
||||
if (!extension_loaded('soap')) {
|
||||
require_once 'Zend/Soap/Server/Exception.php';
|
||||
throw new Zend_Soap_Server_Exception('SOAP extension is not loaded.');
|
||||
}
|
||||
|
||||
@ -161,11 +178,15 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
*
|
||||
* Allows setting options as an associative array of option => value pairs.
|
||||
*
|
||||
* @param array $options
|
||||
* @param array|Zend_Config $options
|
||||
* @return Zend_Soap_Server
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
public function setOptions($options)
|
||||
{
|
||||
if($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
}
|
||||
|
||||
foreach ($options as $key => $value) {
|
||||
switch ($key) {
|
||||
case 'actor':
|
||||
@ -188,6 +209,12 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
case 'wsdl':
|
||||
$this->setWsdl($value);
|
||||
break;
|
||||
case 'featues':
|
||||
$this->setSoapFeatures($value);
|
||||
break;
|
||||
case 'cache_wsdl':
|
||||
$this->setWsdlCache($value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -224,6 +251,14 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
$options['uri'] = $this->_uri;
|
||||
}
|
||||
|
||||
if(null !== $this->_features) {
|
||||
$options['features'] = $this->_features;
|
||||
}
|
||||
|
||||
if(null !== $this->_wsdlCache) {
|
||||
$options['cache_wsdl'] = $this->_wsdlCache;
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
@ -237,6 +272,7 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
public function setEncoding($encoding)
|
||||
{
|
||||
if (!is_string($encoding)) {
|
||||
require_once 'Zend/Soap/Server/Exception.php';
|
||||
throw new Zend_Soap_Server_Exception('Invalid encoding specified');
|
||||
}
|
||||
|
||||
@ -264,6 +300,7 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
public function setSoapVersion($version)
|
||||
{
|
||||
if (!in_array($version, array(SOAP_1_1, SOAP_1_2))) {
|
||||
require_once 'Zend/Soap/Server/Exception.php';
|
||||
throw new Zend_Soap_Server_Exception('Invalid soap version specified');
|
||||
}
|
||||
|
||||
@ -295,6 +332,7 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
return true;
|
||||
}
|
||||
|
||||
require_once 'Zend/Soap/Server/Exception.php';
|
||||
throw new Zend_Soap_Server_Exception('Invalid URN');
|
||||
}
|
||||
|
||||
@ -359,10 +397,18 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
public function setClassmap($classmap)
|
||||
{
|
||||
if (!is_array($classmap)) {
|
||||
/**
|
||||
* @see Zend_Soap_Server_Exception
|
||||
*/
|
||||
require_once 'Zend/Soap/Server/Exception.php';
|
||||
throw new Zend_Soap_Server_Exception('Classmap must be an array');
|
||||
}
|
||||
foreach ($classmap as $type => $class) {
|
||||
if (!class_exists($class)) {
|
||||
/**
|
||||
* @see Zend_Soap_Server_Exception
|
||||
*/
|
||||
require_once 'Zend/Soap/Server/Exception.php';
|
||||
throw new Zend_Soap_Server_Exception('Invalid class in class map');
|
||||
}
|
||||
}
|
||||
@ -389,8 +435,6 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
*/
|
||||
public function setWsdl($wsdl)
|
||||
{
|
||||
is_readable($wsdl);
|
||||
|
||||
$this->_wsdl = $wsdl;
|
||||
return $this;
|
||||
}
|
||||
@ -405,6 +449,48 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
return $this->_wsdl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the SOAP Feature options.
|
||||
*
|
||||
* @param string|int $feature
|
||||
* @return Zend_Soap_Server
|
||||
*/
|
||||
public function setSoapFeatures($feature)
|
||||
{
|
||||
$this->_features = $feature;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current SOAP Features options
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSoapFeatures()
|
||||
{
|
||||
return $this->_features;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the SOAP Wsdl Caching Options
|
||||
*
|
||||
* @param string|int|boolean $caching
|
||||
* @return Zend_Soap_Server
|
||||
*/
|
||||
public function setWsdlCache($options)
|
||||
{
|
||||
$this->_wsdlCache = $options;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current SOAP Wsdl Caching option
|
||||
*/
|
||||
public function getWsdlCache()
|
||||
{
|
||||
return $this->_wsdlCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach a function as a server method
|
||||
*
|
||||
@ -426,6 +512,7 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
if (is_string($func) && function_exists($func)) {
|
||||
$this->_functions[] = $func;
|
||||
} else {
|
||||
require_once 'Zend/Soap/Server/Exception.php';
|
||||
throw new Zend_Soap_Server_Exception('One or more invalid functions specified in array');
|
||||
}
|
||||
}
|
||||
@ -435,6 +522,7 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
} elseif ($function == SOAP_FUNCTIONS_ALL) {
|
||||
$this->_functions = SOAP_FUNCTIONS_ALL;
|
||||
} else {
|
||||
require_once 'Zend/Soap/Server/Exception.php';
|
||||
throw new Zend_Soap_Server_Exception('Invalid function specified');
|
||||
}
|
||||
|
||||
@ -463,14 +551,17 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
public function setClass($class, $arg1 = null, $arg2 = null)
|
||||
{
|
||||
if (isset($this->_class)) {
|
||||
require_once 'Zend/Soap/Server/Exception.php';
|
||||
throw new Zend_Soap_Server_Exception('A class has already been registered with this soap server instance');
|
||||
}
|
||||
|
||||
if (!is_string($class)) {
|
||||
require_once 'Zend/Soap/Server/Exception.php';
|
||||
throw new Zend_Soap_Server_Exception('Invalid class argument (' . gettype($class) . ')');
|
||||
}
|
||||
|
||||
if (!class_exists($class)) {
|
||||
require_once 'Zend/Soap/Server/Exception.php';
|
||||
throw new Zend_Soap_Server_Exception('Class "' . $class . '" does not exist');
|
||||
}
|
||||
|
||||
@ -495,10 +586,12 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
public function setObject($object)
|
||||
{
|
||||
if(!is_object($object)) {
|
||||
require_once 'Zend/Soap/Server/Exception.php';
|
||||
throw new Zend_Soap_Server_Exception('Invalid object argument ('.gettype($object).')');
|
||||
}
|
||||
|
||||
if(isset($this->_object)) {
|
||||
require_once 'Zend/Soap/Server/Exception.php';
|
||||
throw new Zend_Soap_Server_Exception('An object has already been registered with this soap server instance');
|
||||
}
|
||||
|
||||
@ -538,6 +631,7 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
*/
|
||||
public function loadFunctions($definition)
|
||||
{
|
||||
require_once 'Zend/Soap/Server/Exception.php';
|
||||
throw new Zend_Soap_Server_Exception('Unimplemented');
|
||||
}
|
||||
|
||||
@ -550,6 +644,7 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
public function setPersistence($mode)
|
||||
{
|
||||
if (!in_array($mode, array(SOAP_PERSISTENCE_SESSION, SOAP_PERSISTENCE_REQUEST))) {
|
||||
require_once 'Zend/Soap/Server/Exception.php';
|
||||
throw new Zend_Soap_Server_Exception('Invalid persistence mode specified');
|
||||
}
|
||||
|
||||
@ -596,7 +691,8 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
}
|
||||
|
||||
$dom = new DOMDocument();
|
||||
if (!$dom->loadXML($xml)) {
|
||||
if(strlen($xml) == 0 || !$dom->loadXML($xml)) {
|
||||
require_once 'Zend/Soap/Server/Exception.php';
|
||||
throw new Zend_Soap_Server_Exception('Invalid XML');
|
||||
}
|
||||
}
|
||||
@ -712,20 +808,23 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
}
|
||||
|
||||
// Set Zend_Soap_Server error handler
|
||||
$displayErrorsOriginalState = ini_get('display_errors');
|
||||
ini_set('display_errors', false);
|
||||
set_error_handler(array($this, 'handlePhpErrors'), E_USER_ERROR);
|
||||
$displayErrorsOriginalState = $this->_initializeSoapErrorContext();
|
||||
|
||||
$setRequestException = null;
|
||||
/**
|
||||
* @see Zend_Soap_Server_Exception
|
||||
*/
|
||||
require_once 'Zend/Soap/Server/Exception.php';
|
||||
try {
|
||||
$this->_setRequest($request);
|
||||
} catch (Zend_Soap_Server_Exception $setRequestException) {
|
||||
// Do nothing. Catch exception and store it in the $setRequestException variable is all what we need.
|
||||
} catch (Zend_Soap_Server_Exception $e) {
|
||||
$setRequestException = $e;
|
||||
}
|
||||
|
||||
$soap = $this->_getSoap();
|
||||
|
||||
ob_start();
|
||||
if (isset($setRequestException)) {
|
||||
if($setRequestException instanceof Exception) {
|
||||
// Send SOAP fault message if we've catched exception
|
||||
$soap->fault("Sender", $setRequestException->getMessage());
|
||||
} else {
|
||||
@ -750,6 +849,19 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
return $this->_response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method initalizes the error context that the SOAPServer enviroment will run in.
|
||||
*
|
||||
* @return boolean display_errors original value
|
||||
*/
|
||||
protected function _initializeSoapErrorContext()
|
||||
{
|
||||
$displayErrorsOriginalState = ini_get('display_errors');
|
||||
ini_set('display_errors', false);
|
||||
set_error_handler(array($this, 'handlePhpErrors'), E_USER_ERROR);
|
||||
return $displayErrorsOriginalState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a valid fault exception
|
||||
*
|
||||
@ -803,7 +915,7 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
* @param string $code SOAP Fault Codes
|
||||
* @return SoapFault
|
||||
*/
|
||||
public function fault($fault = null, $code = "Reciever")
|
||||
public function fault($fault = null, $code = "Receiver")
|
||||
{
|
||||
if ($fault instanceof Exception) {
|
||||
$class = get_class($fault);
|
||||
@ -825,7 +937,7 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
'Sender', 'Receiver', 'Server'
|
||||
);
|
||||
if(!in_array($code, $allowedFaultModes)) {
|
||||
$code = "Reciever";
|
||||
$code = "Receiver";
|
||||
}
|
||||
|
||||
return new SoapFault($code, $message);
|
||||
@ -844,6 +956,6 @@ class Zend_Soap_Server implements Zend_Server_Interface
|
||||
*/
|
||||
public function handlePhpErrors($errno, $errstr, $errfile = null, $errline = null, array $errcontext = null)
|
||||
{
|
||||
throw $this->fault($errstr, "Reciever");
|
||||
throw $this->fault($errstr, "Receiver");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user