CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.

This commit is contained in:
Paul Baranowski 2011-04-14 18:55:04 -04:00
parent 514777e8d2
commit b11cbd8159
4546 changed files with 138 additions and 51 deletions

View file

@ -0,0 +1,548 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @subpackage AutoDiscover
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: AutoDiscover.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Server_Interface
*/
require_once 'Zend/Server/Interface.php';
/**
* @see Zend_Soap_Wsdl
*/
require_once 'Zend/Soap/Wsdl.php';
/**
* @see Zend_Server_Reflection
*/
require_once 'Zend/Server/Reflection.php';
/**
* @see Zend_Server_Abstract
*/
require_once 'Zend/Server/Abstract.php';
/**
* @see Zend_Uri
*/
require_once 'Zend/Uri.php';
/**
* Zend_Soap_AutoDiscover
*
* @category Zend
* @package Zend_Soap
* @subpackage AutoDiscover
*/
class Zend_Soap_AutoDiscover implements Zend_Server_Interface
{
/**
* @var Zend_Soap_Wsdl
*/
protected $_wsdl = null;
/**
* @var Zend_Server_Reflection
*/
protected $_reflection = null;
/**
* @var array
*/
protected $_functions = array();
/**
* @var boolean
*/
protected $_strategy;
/**
* Url where the WSDL file will be available at.
*
* @var WSDL Uri
*/
protected $_uri;
/**
* soap:body operation style options
*
* @var array
*/
protected $_operationBodyStyle = array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/");
/**
* soap:operation style
*
* @var array
*/
protected $_bindingStyle = array('style' => 'rpc', 'transport' => 'http://schemas.xmlsoap.org/soap/http');
/**
* Constructor
*
* @param boolean|string|Zend_Soap_Wsdl_Strategy_Interface $strategy
* @param string|Zend_Uri $uri
*/
public function __construct($strategy = true, $uri=null)
{
$this->_reflection = new Zend_Server_Reflection();
$this->setComplexTypeStrategy($strategy);
if($uri !== null) {
$this->setUri($uri);
}
}
/**
* Set the location at which the WSDL file will be availabe.
*
* @see Zend_Soap_Exception
* @throws Zend_Soap_AutoDiscover_Exception
* @param Zend_Uri|string $uri
* @return Zend_Soap_AutoDiscover
*/
public function setUri($uri)
{
if(!is_string($uri) && !($uri instanceof Zend_Uri)) {
require_once "Zend/Soap/AutoDiscover/Exception.php";
throw new Zend_Soap_AutoDiscover_Exception("No uri given to Zend_Soap_AutoDiscover::setUri as string or Zend_Uri instance.");
}
$this->_uri = $uri;
// change uri in WSDL file also if existant
if($this->_wsdl instanceof Zend_Soap_Wsdl) {
$this->_wsdl->setUri($uri);
}
return $this;
}
/**
* Return the current Uri that the SOAP WSDL Service will be located at.
*
* @return Zend_Uri
*/
public function getUri()
{
if($this->_uri !== null) {
$uri = $this->_uri;
} else {
$schema = $this->getSchema();
$host = $this->getHostName();
$scriptName = $this->getRequestUriWithoutParameters();
$uri = Zend_Uri::factory($schema . '://' . $host . $scriptName);
$this->setUri($uri);
}
return $uri;
}
/**
* Set options for all the binding operations soap:body elements.
*
* By default the options are set to 'use' => 'encoded' and
* 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/".
*
* @see Zend_Soap_AutoDiscover_Exception
* @param array $operationStyle
* @return Zend_Soap_AutoDiscover
*/
public function setOperationBodyStyle(array $operationStyle=array())
{
if(!isset($operationStyle['use'])) {
require_once "Zend/Soap/AutoDiscover/Exception.php";
throw new Zend_Soap_AutoDiscover_Exception("Key 'use' is required in Operation soap:body style.");
}
$this->_operationBodyStyle = $operationStyle;
return $this;
}
/**
* Set Binding soap:binding style.
*
* By default 'style' is 'rpc' and 'transport' is 'http://schemas.xmlsoap.org/soap/http'.
*
* @param array $bindingStyle
* @return Zend_Soap_AutoDiscover
*/
public function setBindingStyle(array $bindingStyle=array())
{
if(isset($bindingStyle['style'])) {
$this->_bindingStyle['style'] = $bindingStyle['style'];
}
if(isset($bindingStyle['transport'])) {
$this->_bindingStyle['transport'] = $bindingStyle['transport'];
}
return $this;
}
/**
* Detect and returns the current HTTP/HTTPS Schema
*
* @return string
*/
protected function getSchema()
{
$schema = "http";
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$schema = 'https';
}
return $schema;
}
/**
* Detect and return the current hostname
*
* @return string
*/
protected function getHostName()
{
if(isset($_SERVER['HTTP_HOST'])) {
$host = $_SERVER['HTTP_HOST'];
} else {
$host = $_SERVER['SERVER_NAME'];
}
return $host;
}
/**
* Detect and return the current script name without parameters
*
* @return string
*/
protected function getRequestUriWithoutParameters()
{
if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first so IIS will catch
$requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
$requestUri = $_SERVER['REQUEST_URI'];
} elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0, PHP as CGI
$requestUri = $_SERVER['ORIG_PATH_INFO'];
} else {
$requestUri = $_SERVER['SCRIPT_NAME'];
}
if( ($pos = strpos($requestUri, "?")) !== false) {
$requestUri = substr($requestUri, 0, $pos);
}
return $requestUri;
}
/**
* Set the strategy that handles functions and classes that are added AFTER this call.
*
* @param boolean|string|Zend_Soap_Wsdl_Strategy_Interface $strategy
* @return Zend_Soap_AutoDiscover
*/
public function setComplexTypeStrategy($strategy)
{
$this->_strategy = $strategy;
if($this->_wsdl instanceof Zend_Soap_Wsdl) {
$this->_wsdl->setComplexTypeStrategy($strategy);
}
return $this;
}
/**
* Set the Class the SOAP server will use
*
* @param string $class Class Name
* @param string $namespace Class Namspace - Not Used
* @param array $argv Arguments to instantiate the class - Not Used
*/
public function setClass($class, $namespace = '', $argv = null)
{
$uri = $this->getUri();
$wsdl = new Zend_Soap_Wsdl($class, $uri, $this->_strategy);
// The wsdl:types element must precede all other elements (WS-I Basic Profile 1.1 R2023)
$wsdl->addSchemaTypeSection();
$port = $wsdl->addPortType($class . 'Port');
$binding = $wsdl->addBinding($class . 'Binding', 'tns:' .$class. 'Port');
$wsdl->addSoapBinding($binding, $this->_bindingStyle['style'], $this->_bindingStyle['transport']);
$wsdl->addService($class . 'Service', $class . 'Port', 'tns:' . $class . 'Binding', $uri);
foreach ($this->_reflection->reflectClass($class)->getMethods() as $method) {
$this->_addFunctionToWsdl($method, $wsdl, $port, $binding);
}
$this->_wsdl = $wsdl;
}
/**
* Add a Single or Multiple Functions to the WSDL
*
* @param string $function Function Name
* @param string $namespace Function namespace - Not Used
*/
public function addFunction($function, $namespace = '')
{
static $port;
static $operation;
static $binding;
if (!is_array($function)) {
$function = (array) $function;
}
$uri = $this->getUri();
if (!($this->_wsdl instanceof Zend_Soap_Wsdl)) {
$parts = explode('.', basename($_SERVER['SCRIPT_NAME']));
$name = $parts[0];
$wsdl = new Zend_Soap_Wsdl($name, $uri, $this->_strategy);
// The wsdl:types element must precede all other elements (WS-I Basic Profile 1.1 R2023)
$wsdl->addSchemaTypeSection();
$port = $wsdl->addPortType($name . 'Port');
$binding = $wsdl->addBinding($name . 'Binding', 'tns:' .$name. 'Port');
$wsdl->addSoapBinding($binding, $this->_bindingStyle['style'], $this->_bindingStyle['transport']);
$wsdl->addService($name . 'Service', $name . 'Port', 'tns:' . $name . 'Binding', $uri);
} else {
$wsdl = $this->_wsdl;
}
foreach ($function as $func) {
$method = $this->_reflection->reflectFunction($func);
$this->_addFunctionToWsdl($method, $wsdl, $port, $binding);
}
$this->_wsdl = $wsdl;
}
/**
* Add a function to the WSDL document.
*
* @param $function Zend_Server_Reflection_Function_Abstract function to add
* @param $wsdl Zend_Soap_Wsdl WSDL document
* @param $port object wsdl:portType
* @param $binding object wsdl:binding
* @return void
*/
protected function _addFunctionToWsdl($function, $wsdl, $port, $binding)
{
$uri = $this->getUri();
// We only support one prototype: the one with the maximum number of arguments
$prototype = null;
$maxNumArgumentsOfPrototype = -1;
foreach ($function->getPrototypes() as $tmpPrototype) {
$numParams = count($tmpPrototype->getParameters());
if ($numParams > $maxNumArgumentsOfPrototype) {
$maxNumArgumentsOfPrototype = $numParams;
$prototype = $tmpPrototype;
}
}
if ($prototype === null) {
require_once "Zend/Soap/AutoDiscover/Exception.php";
throw new Zend_Soap_AutoDiscover_Exception("No prototypes could be found for the '" . $function->getName() . "' function");
}
// Add the input message (parameters)
$args = array();
if ($this->_bindingStyle['style'] == 'document') {
// Document style: wrap all parameters in a sequence element
$sequence = array();
foreach ($prototype->getParameters() as $param) {
$sequenceElement = array(
'name' => $param->getName(),
'type' => $wsdl->getType($param->getType())
);
if ($param->isOptional()) {
$sequenceElement['nillable'] = 'true';
}
$sequence[] = $sequenceElement;
}
$element = array(
'name' => $function->getName(),
'sequence' => $sequence
);
// Add the wrapper element part, which must be named 'parameters'
$args['parameters'] = array('element' => $wsdl->addElement($element));
} else {
// RPC style: add each parameter as a typed part
foreach ($prototype->getParameters() as $param) {
$args[$param->getName()] = array('type' => $wsdl->getType($param->getType()));
}
}
$wsdl->addMessage($function->getName() . 'In', $args);
$isOneWayMessage = false;
if($prototype->getReturnType() == "void") {
$isOneWayMessage = true;
}
if($isOneWayMessage == false) {
// Add the output message (return value)
$args = array();
if ($this->_bindingStyle['style'] == 'document') {
// Document style: wrap the return value in a sequence element
$sequence = array();
if ($prototype->getReturnType() != "void") {
$sequence[] = array(
'name' => $function->getName() . 'Result',
'type' => $wsdl->getType($prototype->getReturnType())
);
}
$element = array(
'name' => $function->getName() . 'Response',
'sequence' => $sequence
);
// Add the wrapper element part, which must be named 'parameters'
$args['parameters'] = array('element' => $wsdl->addElement($element));
} else if ($prototype->getReturnType() != "void") {
// RPC style: add the return value as a typed part
$args['return'] = array('type' => $wsdl->getType($prototype->getReturnType()));
}
$wsdl->addMessage($function->getName() . 'Out', $args);
}
// Add the portType operation
if($isOneWayMessage == false) {
$portOperation = $wsdl->addPortOperation($port, $function->getName(), 'tns:' . $function->getName() . 'In', 'tns:' . $function->getName() . 'Out');
} else {
$portOperation = $wsdl->addPortOperation($port, $function->getName(), 'tns:' . $function->getName() . 'In', false);
}
$desc = $function->getDescription();
if (strlen($desc) > 0) {
$wsdl->addDocumentation($portOperation, $desc);
}
// When using the RPC style, make sure the operation style includes a 'namespace' attribute (WS-I Basic Profile 1.1 R2717)
if ($this->_bindingStyle['style'] == 'rpc' && !isset($this->_operationBodyStyle['namespace'])) {
$this->_operationBodyStyle['namespace'] = ''.$uri;
}
// Add the binding operation
$operation = $wsdl->addBindingOperation($binding, $function->getName(), $this->_operationBodyStyle, $this->_operationBodyStyle);
$wsdl->addSoapOperation($operation, $uri . '#' .$function->getName());
// Add the function name to the list
$this->_functions[] = $function->getName();
}
/**
* Action to take when an error occurs
*
* @param string $fault
* @param string|int $code
*/
public function fault($fault = null, $code = null)
{
require_once "Zend/Soap/AutoDiscover/Exception.php";
throw new Zend_Soap_AutoDiscover_Exception("Function has no use in AutoDiscover.");
}
/**
* Handle the Request
*
* @param string $request A non-standard request - Not Used
*/
public function handle($request = false)
{
if (!headers_sent()) {
header('Content-Type: text/xml');
}
$this->_wsdl->dump();
}
/**
* Proxy to WSDL dump function
*
* @param string $filename
*/
public function dump($filename)
{
if($this->_wsdl !== null) {
return $this->_wsdl->dump($filename);
} else {
/**
* @see Zend_Soap_AutoDiscover_Exception
*/
require_once "Zend/Soap/AutoDiscover/Exception.php";
throw new Zend_Soap_AutoDiscover_Exception("Cannot dump autodiscovered contents, WSDL file has not been generated yet.");
}
}
/**
* Proxy to WSDL toXml() function
*/
public function toXml()
{
if($this->_wsdl !== null) {
return $this->_wsdl->toXml();
} else {
/**
* @see Zend_Soap_AutoDiscover_Exception
*/
require_once "Zend/Soap/AutoDiscover/Exception.php";
throw new Zend_Soap_AutoDiscover_Exception("Cannot return autodiscovered contents, WSDL file has not been generated yet.");
}
}
/**
* Return an array of functions in the WSDL
*
* @return array
*/
public function getFunctions()
{
return $this->_functions;
}
/**
* Load Functions
*
* @param unknown_type $definition
*/
public function loadFunctions($definition)
{
require_once "Zend/Soap/AutoDiscover/Exception.php";
throw new Zend_Soap_AutoDiscover_Exception("Function has no use in AutoDiscover.");
}
/**
* Set Persistance
*
* @param int $mode
*/
public function setPersistence($mode)
{
require_once "Zend/Soap/AutoDiscover/Exception.php";
throw new Zend_Soap_AutoDiscover_Exception("Function has no use in AutoDiscover.");
}
/**
* Returns an XSD Type for the given PHP type
*
* @param string $type PHP Type to get the XSD type for
* @return string
*/
public function getType($type)
{
if (!($this->_wsdl instanceof Zend_Soap_Wsdl)) {
/** @todo Exception throwing may be more correct */
// WSDL is not defined yet, so we can't recognize type in context of current service
return '';
} else {
return $this->_wsdl->getType($type);
}
}
}

View file

@ -0,0 +1,34 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @subpackage AutoDiscover
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Exception
*/
require_once "Zend/Exception.php";
/**
* @package Zend_Soap
* @subpackage AutoDiscover
*/
class Zend_Soap_AutoDiscover_Exception extends Zend_Exception
{
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,76 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Common.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
if (extension_loaded('soap')) {
/**
* @category Zend
* @package Zend_Soap
* @subpackage Client
*/
class Zend_Soap_Client_Common extends SoapClient
{
/**
* doRequest() pre-processing method
*
* @var callback
*/
protected $_doRequestCallback;
/**
* Common Soap Client constructor
*
* @param callback $doRequestMethod
* @param string $wsdl
* @param array $options
*/
function __construct($doRequestCallback, $wsdl, $options)
{
$this->_doRequestCallback = $doRequestCallback;
parent::__construct($wsdl, $options);
}
/**
* Performs SOAP request over HTTP.
* Overridden to implement different transport layers, perform additional XML processing or other purpose.
*
* @param string $request
* @param string $location
* @param string $action
* @param int $version
* @param int $one_way
* @return mixed
*/
function __doRequest($request, $location, $action, $version, $one_way = null)
{
if ($one_way === null) {
return call_user_func($this->_doRequestCallback, $this, $request, $location, $action, $version);
} else {
return call_user_func($this->_doRequestCallback, $this, $request, $location, $action, $version, $one_way);
}
}
}
} // end if (extension_loaded('soap')

View file

@ -0,0 +1,95 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DotNet.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Soap_Client */
require_once 'Zend/Soap/Client.php';
if (extension_loaded('soap')) {
/**
* Zend_Soap_Client_Local
*
* Class is intended to be used with .Net Web Services.
*
* Important! Class is at experimental stage now.
* Please leave your notes, compatiblity issues reports or
* suggestions in fw-webservices@lists.zend.com or fw-general@lists.com
*
* @category Zend
* @package Zend_Soap
* @subpackage Client
*/
class Zend_Soap_Client_DotNet extends Zend_Soap_Client
{
/**
* Constructor
*
* @param string $wsdl
* @param array $options
*/
public function __construct($wsdl = null, $options = null)
{
// Use SOAP 1.1 as default
$this->setSoapVersion(SOAP_1_1);
parent::__construct($wsdl, $options);
}
/**
* Perform arguments pre-processing
*
* My be overridden in descendant classes
*
* @param array $arguments
* @throws Zend_Soap_Client_Exception
*/
protected function _preProcessArguments($arguments)
{
if (count($arguments) > 1 ||
(count($arguments) == 1 && !is_array(reset($arguments)))
) {
require_once 'Zend/Soap/Client/Exception.php';
throw new Zend_Soap_Client_Exception('.Net webservice arguments have to be grouped into array: array(\'a\' => $a, \'b\' => $b, ...).');
}
// Do nothing
return $arguments;
}
/**
* Perform result pre-processing
*
* My be overridden in descendant classes
*
* @param array $arguments
*/
protected function _preProcessResult($result)
{
$resultProperty = $this->getLastMethod() . 'Result';
return $result->$resultProperty;
}
}
} // end if (extension_loaded('soap')

View file

@ -0,0 +1,35 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Exception */
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Soap
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Soap_Client_Exception extends Zend_Exception
{}

View file

@ -0,0 +1,93 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Local.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Soap_Server */
require_once 'Zend/Soap/Server.php';
/** Zend_Soap_Client */
require_once 'Zend/Soap/Client.php';
if (extension_loaded('soap')) {
/**
* Zend_Soap_Client_Local
*
* Class is intended to be used as local SOAP client which works
* with a provided Server object.
*
* Could be used for development or testing purposes.
*
* @category Zend
* @package Zend_Soap
* @subpackage Client
*/
class Zend_Soap_Client_Local extends Zend_Soap_Client
{
/**
* Server object
*
* @var Zend_Soap_Server
*/
protected $_server;
/**
* Local client constructor
*
* @param Zend_Soap_Server $server
* @param string $wsdl
* @param array $options
*/
function __construct(Zend_Soap_Server $server, $wsdl, $options = null)
{
$this->_server = $server;
// Use Server specified SOAP version as default
$this->setSoapVersion($server->getSoapVersion());
parent::__construct($wsdl, $options);
}
/**
* Actual "do request" method.
*
* @internal
* @param Zend_Soap_Client_Common $client
* @param string $request
* @param string $location
* @param string $action
* @param int $version
* @param int $one_way
* @return mixed
*/
public function _doRequest(Zend_Soap_Client_Common $client, $request, $location, $action, $version, $one_way = null)
{
// Perform request as is
ob_start();
$this->_server->handle($request);
$response = ob_get_contents();
ob_end_clean();
return $response;
}
}
} // end if (extension_loaded('soap')

View file

@ -0,0 +1,959 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @subpackage Server
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Server_Interface
*/
require_once 'Zend/Server/Interface.php';
/**
* Zend_Soap_Server
*
* @category Zend
* @package Zend_Soap
* @subpackage Server
* @uses Zend_Server_Interface
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Server.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Soap_Server implements Zend_Server_Interface
{
/**
* Actor URI
* @var string URI
*/
protected $_actor;
/**
* Class registered with this server
* @var string
*/
protected $_class;
/**
* Arguments to pass to {@link $_class} constructor
* @var array
*/
protected $_classArgs = array();
/**
* Object registered with this server
*/
protected $_object;
/**
* Array of SOAP type => PHP class pairings for handling return/incoming values
* @var array
*/
protected $_classmap;
/**
* Encoding
* @var string
*/
protected $_encoding;
/**
* SOAP Server Features
*
* @var int
*/
protected $_features;
/**
* WSDL Caching Options of SOAP Server
*
* @var mixed
*/
protected $_wsdlCache;
/**
* Registered fault exceptions
* @var array
*/
protected $_faultExceptions = array();
/**
* Functions registered with this server; may be either an array or the SOAP_FUNCTIONS_ALL
* constant
* @var array|int
*/
protected $_functions = array();
/**
* Persistence mode; should be one of the SOAP persistence constants
* @var int
*/
protected $_persistence;
/**
* Request XML
* @var string
*/
protected $_request;
/**
* Response XML
* @var string
*/
protected $_response;
/**
* Flag: whether or not {@link handle()} should return a response instead
* of automatically emitting it.
* @var boolean
*/
protected $_returnResponse = false;
/**
* SOAP version to use; SOAP_1_2 by default, to allow processing of headers
* @var int
*/
protected $_soapVersion = SOAP_1_2;
/**
* URI or path to WSDL
* @var string
*/
protected $_wsdl;
/**
* URI namespace for SOAP server
* @var string URI
*/
protected $_uri;
/**
* Constructor
*
* Sets display_errors INI setting to off (prevent client errors due to bad
* XML in response). Registers {@link handlePhpErrors()} as error handler
* for E_USER_ERROR.
*
* If $wsdl is provided, it is passed on to {@link setWsdl()}; if any
* options are specified, they are passed on to {@link setOptions()}.
*
* @param string $wsdl
* @param array $options
* @return void
*/
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.');
}
if (null !== $wsdl) {
$this->setWsdl($wsdl);
}
if (null !== $options) {
$this->setOptions($options);
}
}
/**
* Set Options
*
* Allows setting options as an associative array of option => value pairs.
*
* @param array|Zend_Config $options
* @return Zend_Soap_Server
*/
public function setOptions($options)
{
if($options instanceof Zend_Config) {
$options = $options->toArray();
}
foreach ($options as $key => $value) {
switch ($key) {
case 'actor':
$this->setActor($value);
break;
case 'classmap':
case 'classMap':
$this->setClassmap($value);
break;
case 'encoding':
$this->setEncoding($value);
break;
case 'soapVersion':
case 'soap_version':
$this->setSoapVersion($value);
break;
case 'uri':
$this->setUri($value);
break;
case 'wsdl':
$this->setWsdl($value);
break;
case 'featues':
$this->setSoapFeatures($value);
break;
case 'cache_wsdl':
$this->setWsdlCache($value);
break;
default:
break;
}
}
return $this;
}
/**
* Return array of options suitable for using with SoapServer constructor
*
* @return array
*/
public function getOptions()
{
$options = array();
if (null !== $this->_actor) {
$options['actor'] = $this->_actor;
}
if (null !== $this->_classmap) {
$options['classmap'] = $this->_classmap;
}
if (null !== $this->_encoding) {
$options['encoding'] = $this->_encoding;
}
if (null !== $this->_soapVersion) {
$options['soap_version'] = $this->_soapVersion;
}
if (null !== $this->_uri) {
$options['uri'] = $this->_uri;
}
if(null !== $this->_features) {
$options['features'] = $this->_features;
}
if(null !== $this->_wsdlCache) {
$options['cache_wsdl'] = $this->_wsdlCache;
}
return $options;
}
/**
* Set encoding
*
* @param string $encoding
* @return Zend_Soap_Server
* @throws Zend_Soap_Server_Exception with invalid encoding argument
*/
public function setEncoding($encoding)
{
if (!is_string($encoding)) {
require_once 'Zend/Soap/Server/Exception.php';
throw new Zend_Soap_Server_Exception('Invalid encoding specified');
}
$this->_encoding = $encoding;
return $this;
}
/**
* Get encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* Set SOAP version
*
* @param int $version One of the SOAP_1_1 or SOAP_1_2 constants
* @return Zend_Soap_Server
* @throws Zend_Soap_Server_Exception with invalid soap version argument
*/
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');
}
$this->_soapVersion = $version;
return $this;
}
/**
* Get SOAP version
*
* @return int
*/
public function getSoapVersion()
{
return $this->_soapVersion;
}
/**
* Check for valid URN
*
* @param string $urn
* @return true
* @throws Zend_Soap_Server_Exception on invalid URN
*/
public function validateUrn($urn)
{
$scheme = parse_url($urn, PHP_URL_SCHEME);
if ($scheme === false || $scheme === null) {
require_once 'Zend/Soap/Server/Exception.php';
throw new Zend_Soap_Server_Exception('Invalid URN');
}
return true;
}
/**
* Set actor
*
* Actor is the actor URI for the server.
*
* @param string $actor
* @return Zend_Soap_Server
*/
public function setActor($actor)
{
$this->validateUrn($actor);
$this->_actor = $actor;
return $this;
}
/**
* Retrieve actor
*
* @return string
*/
public function getActor()
{
return $this->_actor;
}
/**
* Set URI
*
* URI in SoapServer is actually the target namespace, not a URI; $uri must begin with 'urn:'.
*
* @param string $uri
* @return Zend_Soap_Server
* @throws Zend_Soap_Server_Exception with invalid uri argument
*/
public function setUri($uri)
{
$this->validateUrn($uri);
$this->_uri = $uri;
return $this;
}
/**
* Retrieve URI
*
* @return string
*/
public function getUri()
{
return $this->_uri;
}
/**
* Set classmap
*
* @param array $classmap
* @return Zend_Soap_Server
* @throws Zend_Soap_Server_Exception for any invalid class in the class map
*/
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');
}
}
$this->_classmap = $classmap;
return $this;
}
/**
* Retrieve classmap
*
* @return mixed
*/
public function getClassmap()
{
return $this->_classmap;
}
/**
* Set wsdl
*
* @param string $wsdl URI or path to a WSDL
* @return Zend_Soap_Server
*/
public function setWsdl($wsdl)
{
$this->_wsdl = $wsdl;
return $this;
}
/**
* Retrieve wsdl
*
* @return string
*/
public function getWsdl()
{
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
*
* @param array|string $function Function name, array of function names to attach,
* or SOAP_FUNCTIONS_ALL to attach all functions
* @param string $namespace Ignored
* @return Zend_Soap_Server
* @throws Zend_Soap_Server_Exception on invalid functions
*/
public function addFunction($function, $namespace = '')
{
// Bail early if set to SOAP_FUNCTIONS_ALL
if ($this->_functions == SOAP_FUNCTIONS_ALL) {
return $this;
}
if (is_array($function)) {
foreach ($function as $func) {
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');
}
}
$this->_functions = array_merge($this->_functions, $function);
} elseif (is_string($function) && function_exists($function)) {
$this->_functions[] = $function;
} 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');
}
if (is_array($this->_functions)) {
$this->_functions = array_unique($this->_functions);
}
return $this;
}
/**
* Attach a class to a server
*
* Accepts a class name to use when handling requests. Any additional
* arguments will be passed to that class' constructor when instantiated.
*
* See {@link setObject()} to set preconfigured object instances as request handlers.
*
* @param string $class Class Name which executes SOAP Requests at endpoint.
* @return Zend_Soap_Server
* @throws Zend_Soap_Server_Exception if called more than once, or if class
* does not exist
*/
public function setClass($class, $namespace = '', $argv = 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');
}
$this->_class = $class;
if (1 < func_num_args()) {
$argv = func_get_args();
array_shift($argv);
$this->_classArgs = $argv;
}
return $this;
}
/**
* Attach an object to a server
*
* Accepts an instanciated object to use when handling requests.
*
* @param object $object
* @return Zend_Soap_Server
*/
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');
}
$this->_object = $object;
return $this;
}
/**
* Return a server definition array
*
* Returns a list of all functions registered with {@link addFunction()},
* merged with all public methods of the class set with {@link setClass()}
* (if any).
*
* @access public
* @return array
*/
public function getFunctions()
{
$functions = array();
if (null !== $this->_class) {
$functions = get_class_methods($this->_class);
} elseif (null !== $this->_object) {
$functions = get_class_methods($this->_object);
}
return array_merge((array) $this->_functions, $functions);
}
/**
* Unimplemented: Load server definition
*
* @param array $array
* @return void
* @throws Zend_Soap_Server_Exception Unimplemented
*/
public function loadFunctions($definition)
{
require_once 'Zend/Soap/Server/Exception.php';
throw new Zend_Soap_Server_Exception('Unimplemented');
}
/**
* Set server persistence
*
* @param int $mode
* @return Zend_Soap_Server
*/
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');
}
$this->_persistence = $mode;
return $this;
}
/**
* Get server persistence
*
* @return Zend_Soap_Server
*/
public function getPersistence()
{
return $this->_persistence;
}
/**
* Set request
*
* $request may be any of:
* - DOMDocument; if so, then cast to XML
* - DOMNode; if so, then grab owner document and cast to XML
* - SimpleXMLElement; if so, then cast to XML
* - stdClass; if so, calls __toString() and verifies XML
* - string; if so, verifies XML
*
* @param DOMDocument|DOMNode|SimpleXMLElement|stdClass|string $request
* @return Zend_Soap_Server
*/
protected function _setRequest($request)
{
if ($request instanceof DOMDocument) {
$xml = $request->saveXML();
} elseif ($request instanceof DOMNode) {
$xml = $request->ownerDocument->saveXML();
} elseif ($request instanceof SimpleXMLElement) {
$xml = $request->asXML();
} elseif (is_object($request) || is_string($request)) {
if (is_object($request)) {
$xml = $request->__toString();
} else {
$xml = $request;
}
$dom = new DOMDocument();
if(strlen($xml) == 0 || !$dom->loadXML($xml)) {
require_once 'Zend/Soap/Server/Exception.php';
throw new Zend_Soap_Server_Exception('Invalid XML');
}
}
$this->_request = $xml;
return $this;
}
/**
* Retrieve request XML
*
* @return string
*/
public function getLastRequest()
{
return $this->_request;
}
/**
* Set return response flag
*
* If true, {@link handle()} will return the response instead of
* automatically sending it back to the requesting client.
*
* The response is always available via {@link getResponse()}.
*
* @param boolean $flag
* @return Zend_Soap_Server
*/
public function setReturnResponse($flag)
{
$this->_returnResponse = ($flag) ? true : false;
return $this;
}
/**
* Retrieve return response flag
*
* @return boolean
*/
public function getReturnResponse()
{
return $this->_returnResponse;
}
/**
* Get response XML
*
* @return string
*/
public function getLastResponse()
{
return $this->_response;
}
/**
* Get SoapServer object
*
* Uses {@link $_wsdl} and return value of {@link getOptions()} to instantiate
* SoapServer object, and then registers any functions or class with it, as
* well as peristence.
*
* @return SoapServer
*/
protected function _getSoap()
{
$options = $this->getOptions();
$server = new SoapServer($this->_wsdl, $options);
if (!empty($this->_functions)) {
$server->addFunction($this->_functions);
}
if (!empty($this->_class)) {
$args = $this->_classArgs;
array_unshift($args, $this->_class);
call_user_func_array(array($server, 'setClass'), $args);
}
if (!empty($this->_object)) {
$server->setObject($this->_object);
}
if (null !== $this->_persistence) {
$server->setPersistence($this->_persistence);
}
return $server;
}
/**
* Handle a request
*
* Instantiates SoapServer object with options set in object, and
* dispatches its handle() method.
*
* $request may be any of:
* - DOMDocument; if so, then cast to XML
* - DOMNode; if so, then grab owner document and cast to XML
* - SimpleXMLElement; if so, then cast to XML
* - stdClass; if so, calls __toString() and verifies XML
* - string; if so, verifies XML
*
* If no request is passed, pulls request using php:://input (for
* cross-platform compatability purposes).
*
* @param DOMDocument|DOMNode|SimpleXMLElement|stdClass|string $request Optional request
* @return void|string
*/
public function handle($request = null)
{
if (null === $request) {
$request = file_get_contents('php://input');
}
// Set Zend_Soap_Server error handler
$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 $e) {
$setRequestException = $e;
}
$soap = $this->_getSoap();
ob_start();
if($setRequestException instanceof Exception) {
// Send SOAP fault message if we've catched exception
$soap->fault("Sender", $setRequestException->getMessage());
} else {
try {
$soap->handle($request);
} catch (Exception $e) {
$fault = $this->fault($e);
$soap->fault($fault->faultcode, $fault->faultstring);
}
}
$this->_response = ob_get_clean();
// Restore original error handler
restore_error_handler();
ini_set('display_errors', $displayErrorsOriginalState);
if (!$this->_returnResponse) {
echo $this->_response;
return;
}
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
*
* @param string|array $class Exception class or array of exception classes
* @return Zend_Soap_Server
*/
public function registerFaultException($class)
{
$this->_faultExceptions = array_merge($this->_faultExceptions, (array) $class);
return $this;
}
/**
* Deregister a fault exception from the fault exception stack
*
* @param string $class
* @return boolean
*/
public function deregisterFaultException($class)
{
if (in_array($class, $this->_faultExceptions, true)) {
$index = array_search($class, $this->_faultExceptions);
unset($this->_faultExceptions[$index]);
return true;
}
return false;
}
/**
* Return fault exceptions list
*
* @return array
*/
public function getFaultExceptions()
{
return $this->_faultExceptions;
}
/**
* Generate a server fault
*
* Note that the arguments are reverse to those of SoapFault.
*
* If an exception is passed as the first argument, its message and code
* will be used to create the fault object if it has been registered via
* {@Link registerFaultException()}.
*
* @link http://www.w3.org/TR/soap12-part1/#faultcodes
* @param string|Exception $fault
* @param string $code SOAP Fault Codes
* @return SoapFault
*/
public function fault($fault = null, $code = "Receiver")
{
if ($fault instanceof Exception) {
$class = get_class($fault);
if (in_array($class, $this->_faultExceptions)) {
$message = $fault->getMessage();
$eCode = $fault->getCode();
$code = empty($eCode) ? $code : $eCode;
} else {
$message = 'Unknown error';
}
} elseif(is_string($fault)) {
$message = $fault;
} else {
$message = 'Unknown error';
}
$allowedFaultModes = array(
'VersionMismatch', 'MustUnderstand', 'DataEncodingUnknown',
'Sender', 'Receiver', 'Server'
);
if(!in_array($code, $allowedFaultModes)) {
$code = "Receiver";
}
return new SoapFault($code, $message);
}
/**
* Throw PHP errors as SoapFaults
*
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param int $errline
* @param array $errcontext
* @return void
* @throws SoapFault
*/
public function handlePhpErrors($errno, $errstr, $errfile = null, $errline = null, array $errcontext = null)
{
throw $this->fault($errstr, "Receiver");
}
}

View file

@ -0,0 +1,37 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @subpackage Server
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Exception */
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Soap
* @subpackage Server
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Soap_Server_Exception extends Zend_Exception
{}

View file

@ -0,0 +1,666 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Wsdl.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Soap_Wsdl_Strategy_Interface
*/
require_once "Zend/Soap/Wsdl/Strategy/Interface.php";
/**
* @see Zend_Soap_Wsdl_Strategy_Abstract
*/
require_once "Zend/Soap/Wsdl/Strategy/Abstract.php";
/**
* Zend_Soap_Wsdl
*
* @category Zend
* @package Zend_Soap
*/
class Zend_Soap_Wsdl
{
/**
* @var object DomDocument Instance
*/
private $_dom;
/**
* @var object WSDL Root XML_Tree_Node
*/
private $_wsdl;
/**
* @var string URI where the WSDL will be available
*/
private $_uri;
/**
* @var DOMElement
*/
private $_schema = null;
/**
* Types defined on schema
*
* @var array
*/
private $_includedTypes = array();
/**
* Strategy for detection of complex types
*/
protected $_strategy = null;
/**
* Constructor
*
* @param string $name Name of the Web Service being Described
* @param string $uri URI where the WSDL will be available
* @param boolean|string|Zend_Soap_Wsdl_Strategy_Interface $strategy
*/
public function __construct($name, $uri, $strategy = true)
{
if ($uri instanceof Zend_Uri_Http) {
$uri = $uri->getUri();
}
$this->_uri = $uri;
/**
* @todo change DomDocument object creation from cparsing to construxting using API
* It also should authomatically escape $name and $uri values if necessary
*/
$wsdl = "<?xml version='1.0' ?>
<definitions name='$name' targetNamespace='$uri'
xmlns='http://schemas.xmlsoap.org/wsdl/'
xmlns:tns='$uri'
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:soap-enc='http://schemas.xmlsoap.org/soap/encoding/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'></definitions>";
$this->_dom = new DOMDocument();
if (!$this->_dom->loadXML($wsdl)) {
require_once 'Zend/Server/Exception.php';
throw new Zend_Server_Exception('Unable to create DomDocument');
} else {
$this->_wsdl = $this->_dom->documentElement;
}
$this->setComplexTypeStrategy($strategy);
}
/**
* Set a new uri for this WSDL
*
* @param string|Zend_Uri_Http $uri
* @return Zend_Server_Wsdl
*/
public function setUri($uri)
{
if ($uri instanceof Zend_Uri_Http) {
$uri = $uri->getUri();
}
$oldUri = $this->_uri;
$this->_uri = $uri;
if($this->_dom !== null) {
// @todo: This is the worst hack ever, but its needed due to design and non BC issues of WSDL generation
$xml = $this->_dom->saveXML();
$xml = str_replace($oldUri, $uri, $xml);
$this->_dom = new DOMDocument();
$this->_dom->loadXML($xml);
}
return $this;
}
/**
* Set a strategy for complex type detection and handling
*
* @todo Boolean is for backwards compability with extractComplexType object var. Remove it in later versions.
* @param boolean|string|Zend_Soap_Wsdl_Strategy_Interface $strategy
* @return Zend_Soap_Wsdl
*/
public function setComplexTypeStrategy($strategy)
{
if($strategy === true) {
require_once "Zend/Soap/Wsdl/Strategy/DefaultComplexType.php";
$strategy = new Zend_Soap_Wsdl_Strategy_DefaultComplexType();
} else if($strategy === false) {
require_once "Zend/Soap/Wsdl/Strategy/AnyType.php";
$strategy = new Zend_Soap_Wsdl_Strategy_AnyType();
} else if(is_string($strategy)) {
if(class_exists($strategy)) {
$strategy = new $strategy();
} else {
require_once "Zend/Soap/Wsdl/Exception.php";
throw new Zend_Soap_Wsdl_Exception(
sprintf("Strategy with name '%s does not exist.", $strategy
));
}
}
if(!($strategy instanceof Zend_Soap_Wsdl_Strategy_Interface)) {
require_once "Zend/Soap/Wsdl/Exception.php";
throw new Zend_Soap_Wsdl_Exception("Set a strategy that is not of type 'Zend_Soap_Wsdl_Strategy_Interface'");
}
$this->_strategy = $strategy;
return $this;
}
/**
* Get the current complex type strategy
*
* @return Zend_Soap_Wsdl_Strategy_Interface
*/
public function getComplexTypeStrategy()
{
return $this->_strategy;
}
/**
* Add a {@link http://www.w3.org/TR/wsdl#_messages message} element to the WSDL
*
* @param string $name Name for the {@link http://www.w3.org/TR/wsdl#_messages message}
* @param array $parts An array of {@link http://www.w3.org/TR/wsdl#_message parts}
* The array is constructed like: 'name of part' => 'part xml schema data type'
* or 'name of part' => array('type' => 'part xml schema type')
* or 'name of part' => array('element' => 'part xml element name')
* @return object The new message's XML_Tree_Node for use in {@link function addDocumentation}
*/
public function addMessage($name, $parts)
{
$message = $this->_dom->createElement('message');
$message->setAttribute('name', $name);
if (sizeof($parts) > 0) {
foreach ($parts as $name => $type) {
$part = $this->_dom->createElement('part');
$part->setAttribute('name', $name);
if (is_array($type)) {
foreach ($type as $key => $value) {
$part->setAttribute($key, $value);
}
} else {
$part->setAttribute('type', $type);
}
$message->appendChild($part);
}
}
$this->_wsdl->appendChild($message);
return $message;
}
/**
* Add a {@link http://www.w3.org/TR/wsdl#_porttypes portType} element to the WSDL
*
* @param string $name portType element's name
* @return object The new portType's XML_Tree_Node for use in {@link function addPortOperation} and {@link function addDocumentation}
*/
public function addPortType($name)
{
$portType = $this->_dom->createElement('portType');
$portType->setAttribute('name', $name);
$this->_wsdl->appendChild($portType);
return $portType;
}
/**
* Add an {@link http://www.w3.org/TR/wsdl#_request-response operation} element to a portType element
*
* @param object $portType a portType XML_Tree_Node, from {@link function addPortType}
* @param string $name Operation name
* @param string $input Input Message
* @param string $output Output Message
* @param string $fault Fault Message
* @return object The new operation's XML_Tree_Node for use in {@link function addDocumentation}
*/
public function addPortOperation($portType, $name, $input = false, $output = false, $fault = false)
{
$operation = $this->_dom->createElement('operation');
$operation->setAttribute('name', $name);
if (is_string($input) && (strlen(trim($input)) >= 1)) {
$node = $this->_dom->createElement('input');
$node->setAttribute('message', $input);
$operation->appendChild($node);
}
if (is_string($output) && (strlen(trim($output)) >= 1)) {
$node= $this->_dom->createElement('output');
$node->setAttribute('message', $output);
$operation->appendChild($node);
}
if (is_string($fault) && (strlen(trim($fault)) >= 1)) {
$node = $this->_dom->createElement('fault');
$node->setAttribute('message', $fault);
$operation->appendChild($node);
}
$portType->appendChild($operation);
return $operation;
}
/**
* Add a {@link http://www.w3.org/TR/wsdl#_bindings binding} element to WSDL
*
* @param string $name Name of the Binding
* @param string $type name of the portType to bind
* @return object The new binding's XML_Tree_Node for use with {@link function addBindingOperation} and {@link function addDocumentation}
*/
public function addBinding($name, $portType)
{
$binding = $this->_dom->createElement('binding');
$binding->setAttribute('name', $name);
$binding->setAttribute('type', $portType);
$this->_wsdl->appendChild($binding);
return $binding;
}
/**
* Add an operation to a binding element
*
* @param object $binding A binding XML_Tree_Node returned by {@link function addBinding}
* @param array $input An array of attributes for the input element, allowed keys are: 'use', 'namespace', 'encodingStyle'. {@link http://www.w3.org/TR/wsdl#_soap:body More Information}
* @param array $output An array of attributes for the output element, allowed keys are: 'use', 'namespace', 'encodingStyle'. {@link http://www.w3.org/TR/wsdl#_soap:body More Information}
* @param array $fault An array of attributes for the fault element, allowed keys are: 'name', 'use', 'namespace', 'encodingStyle'. {@link http://www.w3.org/TR/wsdl#_soap:body More Information}
* @return object The new Operation's XML_Tree_Node for use with {@link function addSoapOperation} and {@link function addDocumentation}
*/
public function addBindingOperation($binding, $name, $input = false, $output = false, $fault = false)
{
$operation = $this->_dom->createElement('operation');
$operation->setAttribute('name', $name);
if (is_array($input)) {
$node = $this->_dom->createElement('input');
$soap_node = $this->_dom->createElement('soap:body');
foreach ($input as $name => $value) {
$soap_node->setAttribute($name, $value);
}
$node->appendChild($soap_node);
$operation->appendChild($node);
}
if (is_array($output)) {
$node = $this->_dom->createElement('output');
$soap_node = $this->_dom->createElement('soap:body');
foreach ($output as $name => $value) {
$soap_node->setAttribute($name, $value);
}
$node->appendChild($soap_node);
$operation->appendChild($node);
}
if (is_array($fault)) {
$node = $this->_dom->createElement('fault');
if (isset($fault['name'])) {
$node->setAttribute('name', $fault['name']);
}
$soap_node = $this->_dom->createElement('soap:body');
foreach ($output as $name => $value) {
$soap_node->setAttribute($name, $value);
}
$node->appendChild($soap_node);
$operation->appendChild($node);
}
$binding->appendChild($operation);
return $operation;
}
/**
* Add a {@link http://www.w3.org/TR/wsdl#_soap:binding SOAP binding} element to a Binding element
*
* @param object $binding A binding XML_Tree_Node returned by {@link function addBinding}
* @param string $style binding style, possible values are "rpc" (the default) and "document"
* @param string $transport Transport method (defaults to HTTP)
* @return boolean
*/
public function addSoapBinding($binding, $style = 'document', $transport = 'http://schemas.xmlsoap.org/soap/http')
{
$soap_binding = $this->_dom->createElement('soap:binding');
$soap_binding->setAttribute('style', $style);
$soap_binding->setAttribute('transport', $transport);
$binding->appendChild($soap_binding);
return $soap_binding;
}
/**
* Add a {@link http://www.w3.org/TR/wsdl#_soap:operation SOAP operation} to an operation element
*
* @param object $operation An operation XML_Tree_Node returned by {@link function addBindingOperation}
* @param string $soap_action SOAP Action
* @return boolean
*/
public function addSoapOperation($binding, $soap_action)
{
if ($soap_action instanceof Zend_Uri_Http) {
$soap_action = $soap_action->getUri();
}
$soap_operation = $this->_dom->createElement('soap:operation');
$soap_operation->setAttribute('soapAction', $soap_action);
$binding->insertBefore($soap_operation, $binding->firstChild);
return $soap_operation;
}
/**
* Add a {@link http://www.w3.org/TR/wsdl#_services service} element to the WSDL
*
* @param string $name Service Name
* @param string $port_name Name of the port for the service
* @param string $binding Binding for the port
* @param string $location SOAP Address for the service
* @return object The new service's XML_Tree_Node for use with {@link function addDocumentation}
*/
public function addService($name, $port_name, $binding, $location)
{
if ($location instanceof Zend_Uri_Http) {
$location = $location->getUri();
}
$service = $this->_dom->createElement('service');
$service->setAttribute('name', $name);
$port = $this->_dom->createElement('port');
$port->setAttribute('name', $port_name);
$port->setAttribute('binding', $binding);
$soap_address = $this->_dom->createElement('soap:address');
$soap_address->setAttribute('location', $location);
$port->appendChild($soap_address);
$service->appendChild($port);
$this->_wsdl->appendChild($service);
return $service;
}
/**
* Add a documentation element to any element in the WSDL.
*
* Note that the WSDL {@link http://www.w3.org/TR/wsdl#_documentation specification} uses 'document',
* but the WSDL {@link http://schemas.xmlsoap.org/wsdl/ schema} uses 'documentation' instead.
* The {@link http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html#WSDL_documentation_Element WS-I Basic Profile 1.1} recommends using 'documentation'.
*
* @param object $input_node An XML_Tree_Node returned by another method to add the documentation to
* @param string $documentation Human readable documentation for the node
* @return DOMElement The documentation element
*/
public function addDocumentation($input_node, $documentation)
{
if ($input_node === $this) {
$node = $this->_dom->documentElement;
} else {
$node = $input_node;
}
$doc = $this->_dom->createElement('documentation');
$doc_cdata = $this->_dom->createTextNode($documentation);
$doc->appendChild($doc_cdata);
if($node->hasChildNodes()) {
$node->insertBefore($doc, $node->firstChild);
} else {
$node->appendChild($doc);
}
return $doc;
}
/**
* Add WSDL Types element
*
* @param object $types A DomDocument|DomNode|DomElement|DomDocumentFragment with all the XML Schema types defined in it
*/
public function addTypes($types)
{
if ($types instanceof DomDocument) {
$dom = $this->_dom->importNode($types->documentElement);
$this->_wsdl->appendChild($types->documentElement);
} elseif ($types instanceof DomNode || $types instanceof DomElement || $types instanceof DomDocumentFragment ) {
$dom = $this->_dom->importNode($types);
$this->_wsdl->appendChild($dom);
}
}
/**
* Add a complex type name that is part of this WSDL and can be used in signatures.
*
* @param string $type
* @return Zend_Soap_Wsdl
*/
public function addType($type)
{
if(!in_array($type, $this->_includedTypes)) {
$this->_includedTypes[] = $type;
}
return $this;
}
/**
* Return an array of all currently included complex types
*
* @return array
*/
public function getTypes()
{
return $this->_includedTypes;
}
/**
* Return the Schema node of the WSDL
*
* @return DOMElement
*/
public function getSchema()
{
if($this->_schema == null) {
$this->addSchemaTypeSection();
}
return $this->_schema;
}
/**
* Return the WSDL as XML
*
* @return string WSDL as XML
*/
public function toXML()
{
return $this->_dom->saveXML();
}
/**
* Return DOM Document
*
* @return object DomDocum ent
*/
public function toDomDocument()
{
return $this->_dom;
}
/**
* Echo the WSDL as XML
*
* @return boolean
*/
public function dump($filename = false)
{
if (!$filename) {
echo $this->toXML();
return true;
} else {
return file_put_contents($filename, $this->toXML());
}
}
/**
* Returns an XSD Type for the given PHP type
*
* @param string $type PHP Type to get the XSD type for
* @return string
*/
public function getType($type)
{
switch (strtolower($type)) {
case 'string':
case 'str':
return 'xsd:string';
break;
case 'int':
case 'integer':
return 'xsd:int';
break;
case 'float':
case 'double':
return 'xsd:float';
break;
case 'boolean':
case 'bool':
return 'xsd:boolean';
break;
case 'array':
return 'soap-enc:Array';
break;
case 'object':
return 'xsd:struct';
break;
case 'mixed':
return 'xsd:anyType';
break;
case 'void':
return '';
default:
// delegate retrieval of complex type to current strategy
return $this->addComplexType($type);
}
}
/**
* This function makes sure a complex types section and schema additions are set.
*
* @return Zend_Soap_Wsdl
*/
public function addSchemaTypeSection()
{
if ($this->_schema === null) {
$this->_schema = $this->_dom->createElement('xsd:schema');
$this->_schema->setAttribute('targetNamespace', $this->_uri);
$types = $this->_dom->createElement('types');
$types->appendChild($this->_schema);
$this->_wsdl->appendChild($types);
}
return $this;
}
/**
* Add a {@link http://www.w3.org/TR/wsdl#_types types} data type definition
*
* @param string $type Name of the class to be specified
* @return string XSD Type for the given PHP type
*/
public function addComplexType($type)
{
if (in_array($type, $this->getTypes())) {
return "tns:$type";
}
$this->addSchemaTypeSection();
$strategy = $this->getComplexTypeStrategy();
$strategy->setContext($this);
// delegates the detection of a complex type to the current strategy
return $strategy->addComplexType($type);
}
/**
* Parse an xsd:element represented as an array into a DOMElement.
*
* @param array $element an xsd:element represented as an array
* @return DOMElement parsed element
*/
private function _parseElement($element)
{
if (!is_array($element)) {
require_once "Zend/Soap/Wsdl/Exception.php";
throw new Zend_Soap_Wsdl_Exception("The 'element' parameter needs to be an associative array.");
}
$elementXml = $this->_dom->createElement('xsd:element');
foreach ($element as $key => $value) {
if (in_array($key, array('sequence', 'all', 'choice'))) {
if (is_array($value)) {
$complexType = $this->_dom->createElement('xsd:complexType');
if (count($value) > 0) {
$container = $this->_dom->createElement('xsd:' . $key);
foreach ($value as $subelement) {
$subelementXml = $this->_parseElement($subelement);
$container->appendChild($subelementXml);
}
$complexType->appendChild($container);
}
$elementXml->appendChild($complexType);
}
} else {
$elementXml->setAttribute($key, $value);
}
}
return $elementXml;
}
/**
* Add an xsd:element represented as an array to the schema.
*
* Array keys represent attribute names and values their respective value.
* The 'sequence', 'all' and 'choice' keys must have an array of elements as their value,
* to add them to a nested complexType.
*
* Example: array( 'name' => 'MyElement',
* 'sequence' => array( array('name' => 'myString', 'type' => 'string'),
* array('name' => 'myInteger', 'type' => 'int') ) );
* Resulting XML: <xsd:element name="MyElement"><xsd:complexType><xsd:sequence>
* <xsd:element name="myString" type="string"/>
* <xsd:element name="myInteger" type="int"/>
* </xsd:sequence></xsd:complexType></xsd:element>
*
* @param array $element an xsd:element represented as an array
* @return string xsd:element for the given element array
*/
public function addElement($element)
{
$schema = $this->getSchema();
$elementXml = $this->_parseElement($element);
$schema->appendChild($elementXml);
return 'tns:' . $element['name'];
}
}

View file

@ -0,0 +1,37 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @subpackage Wsdl
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Exception
*/
require_once "Zend/Exception.php";
/**
* Zend_Soap_Wsdl_Exception
*
* @category Zend
* @package Zend_Soap
* @subpackage Wsdl
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Soap_Wsdl_Exception extends Zend_Exception { }

View file

@ -0,0 +1,66 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @subpackage Wsdl
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Soap_Wsdl_Strategy_Interface
*/
require_once "Zend/Soap/Wsdl/Strategy/Interface.php";
/**
* Abstract class for Zend_Soap_Wsdl_Strategy.
*
* @category Zend
* @package Zend_Soap
* @subpackage Wsdl
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Soap_Wsdl_Strategy_Abstract implements Zend_Soap_Wsdl_Strategy_Interface
{
/**
* Context object
*
* @var Zend_Soap_Wsdl
*/
protected $_context;
/**
* Set the Zend_Soap_Wsdl Context object this strategy resides in.
*
* @param Zend_Soap_Wsdl $context
* @return void
*/
public function setContext(Zend_Soap_Wsdl $context)
{
$this->_context = $context;
}
/**
* Return the current Zend_Soap_Wsdl context object
*
* @return Zend_Soap_Wsdl
*/
public function getContext()
{
return $this->_context;
}
}

View file

@ -0,0 +1,59 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @subpackage Wsdl
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: AnyType.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Soap_Wsdl_Strategy_Interface
*/
require_once "Zend/Soap/Wsdl/Strategy/Interface.php";
/**
* Zend_Soap_Wsdl_Strategy_AnyType
*
* @category Zend
* @package Zend_Soap
* @subpackage Wsdl
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Soap_Wsdl_Strategy_AnyType implements Zend_Soap_Wsdl_Strategy_Interface
{
/**
* Not needed in this strategy.
*
* @param Zend_Soap_Wsdl $context
*/
public function setContext(Zend_Soap_Wsdl $context)
{
}
/**
* Returns xsd:anyType regardless of the input.
*
* @param string $type
* @return string
*/
public function addComplexType($type)
{
return 'xsd:anyType';
}
}

View file

@ -0,0 +1,146 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @subpackage Wsdl
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: ArrayOfTypeComplex.php 20784 2010-01-31 08:22:51Z yoshida@zend.co.jp $
*/
/**
* @see Zend_Soap_Wsdl_Strategy_DefaultComplexType
*/
require_once "Zend/Soap/Wsdl/Strategy/DefaultComplexType.php";
/**
* Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex
*
* @category Zend
* @package Zend_Soap
* @subpackage Wsdl
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex extends Zend_Soap_Wsdl_Strategy_DefaultComplexType
{
protected $_inProcess = array();
/**
* Add an ArrayOfType based on the xsd:complexType syntax if type[] is detected in return value doc comment.
*
* @param string $type
* @return string tns:xsd-type
*/
public function addComplexType($type)
{
if(in_array($type, $this->_inProcess)) {
require_once "Zend/Soap/Wsdl/Exception.php";
throw new Zend_Soap_Wsdl_Exception("Infinite recursion, cannot nest '".$type."' into itself.");
}
$this->_inProcess[$type] = $type;
$nestingLevel = $this->_getNestedCount($type);
if($nestingLevel > 1) {
require_once "Zend/Soap/Wsdl/Exception.php";
throw new Zend_Soap_Wsdl_Exception(
"ArrayOfTypeComplex cannot return nested ArrayOfObject deeper than ".
"one level. Use array object properties to return deep nested data.
");
}
$singularType = $this->_getSingularPhpType($type);
if(!class_exists($singularType)) {
require_once "Zend/Soap/Wsdl/Exception.php";
throw new Zend_Soap_Wsdl_Exception(sprintf(
"Cannot add a complex type %s that is not an object or where ".
"class could not be found in 'DefaultComplexType' strategy.", $type
));
}
if($nestingLevel == 1) {
// The following blocks define the Array of Object structure
$xsdComplexTypeName = $this->_addArrayOfComplexType($singularType, $type);
} else {
$xsdComplexTypeName = $singularType;
}
// The array for the objects has been created, now build the object definition:
if(!in_array($singularType, $this->getContext()->getTypes())) {
parent::addComplexType($singularType);
}
unset($this->_inProcess[$type]);
return "tns:".$xsdComplexTypeName;
}
protected function _addArrayOfComplexType($singularType, $type)
{
$dom = $this->getContext()->toDomDocument();
$xsdComplexTypeName = $this->_getXsdComplexTypeName($singularType);
if(!in_array($xsdComplexTypeName, $this->getContext()->getTypes())) {
$complexType = $dom->createElement('xsd:complexType');
$complexType->setAttribute('name', $xsdComplexTypeName);
$complexContent = $dom->createElement("xsd:complexContent");
$complexType->appendChild($complexContent);
$xsdRestriction = $dom->createElement("xsd:restriction");
$xsdRestriction->setAttribute('base', 'soap-enc:Array');
$complexContent->appendChild($xsdRestriction);
$xsdAttribute = $dom->createElement("xsd:attribute");
$xsdAttribute->setAttribute("ref", "soap-enc:arrayType");
$xsdAttribute->setAttribute("wsdl:arrayType", sprintf("tns:%s[]", $singularType));
$xsdRestriction->appendChild($xsdAttribute);
$this->getContext()->getSchema()->appendChild($complexType);
$this->getContext()->addType($xsdComplexTypeName);
}
return $xsdComplexTypeName;
}
protected function _getXsdComplexTypeName($type)
{
return sprintf('ArrayOf%s', $type);
}
/**
* From a nested definition with type[], get the singular PHP Type
*
* @param string $type
* @return string
*/
protected function _getSingularPhpType($type)
{
return str_replace("[]", "", $type);
}
/**
* Return the array nesting level based on the type name
*
* @param string $type
* @return integer
*/
protected function _getNestedCount($type)
{
return substr_count($type, "[]");
}
}

View file

@ -0,0 +1,155 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: ArrayOfTypeSequence.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Soap_Wsdl_Strategy_DefaultComplexType
*/
require_once "Zend/Soap/Wsdl/Strategy/DefaultComplexType.php";
/**
* Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence
*
* @category Zend
* @package Zend_Soap
* @subpackage Wsdl
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence extends Zend_Soap_Wsdl_Strategy_DefaultComplexType
{
/**
* Add an unbounded ArrayOfType based on the xsd:sequence syntax if type[] is detected in return value doc comment.
*
* @param string $type
* @return string tns:xsd-type
*/
public function addComplexType($type)
{
$nestedCounter = $this->_getNestedCount($type);
if($nestedCounter > 0) {
$singularType = $this->_getSingularType($type);
for($i = 1; $i <= $nestedCounter; $i++) {
$complexTypeName = substr($this->_getTypeNameBasedOnNestingLevel($singularType, $i), 4);
$childTypeName = $this->_getTypeNameBasedOnNestingLevel($singularType, $i-1);
$this->_addElementFromWsdlAndChildTypes($complexTypeName, $childTypeName);
}
// adding the PHP type which is resolved to a nested XSD type. therefore add only once.
$this->getContext()->addType($complexTypeName);
return "tns:$complexTypeName";
} else if (!in_array($type, $this->getContext()->getTypes())) {
// New singular complex type
return parent::addComplexType($type);
} else {
// Existing complex type
return $this->getContext()->getType($type);
}
}
/**
* Return the ArrayOf or simple type name based on the singular xsdtype and the nesting level
*
* @param string $singularType
* @param int $level
* @return string
*/
protected function _getTypeNameBasedOnNestingLevel($singularType, $level)
{
if($level == 0) {
// This is not an Array anymore, return the xsd simple type
return $singularType;
} else {
$prefix = str_repeat("ArrayOf", $level);
$xsdType = $this->_getStrippedXsdType($singularType);
$arrayType = $prefix.$xsdType;
return "tns:$arrayType";
}
}
/**
* Strip the xsd: from a singularType and Format it nice for ArrayOf<Type> naming
*
* @param string $singularType
* @return string
*/
protected function _getStrippedXsdType($singularType)
{
return ucfirst(substr(strtolower($singularType), 4));
}
/**
* From a nested defintion with type[], get the singular xsd:type
*
* @throws Zend_Soap_Wsdl_Exception When no xsd:simpletype can be detected.
* @param string $type
* @return string
*/
protected function _getSingularType($type)
{
$singulartype = $this->getContext()->getType(str_replace("[]", "", $type));
return $singulartype;
}
/**
* Return the array nesting level based on the type name
*
* @param string $type
* @return integer
*/
protected function _getNestedCount($type)
{
return substr_count($type, "[]");
}
/**
* Append the complex type definition to the WSDL via the context access
*
* @param string $arrayType
* @param string $childTypeName
* @return void
*/
protected function _addElementFromWsdlAndChildTypes($arrayType, $childTypeName)
{
if (!in_array($arrayType, $this->getContext()->getTypes())) {
$dom = $this->getContext()->toDomDocument();
$complexType = $dom->createElement('xsd:complexType');
$complexType->setAttribute('name', $arrayType);
$sequence = $dom->createElement('xsd:sequence');
$element = $dom->createElement('xsd:element');
$element->setAttribute('name', 'item');
$element->setAttribute('type', $childTypeName);
$element->setAttribute('minOccurs', 0);
$element->setAttribute('maxOccurs', 'unbounded');
$sequence->appendChild($element);
$complexType->appendChild($sequence);
$this->getContext()->getSchema()->appendChild($complexType);
$this->getContext()->addType($arrayType);
}
}
}

View file

@ -0,0 +1,188 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @subpackage Wsdl
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Composite.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Soap_Wsdl_Strategy_Interface
*/
require_once "Zend/Soap/Wsdl/Strategy/Interface.php";
/**
* Zend_Soap_Wsdl_Strategy_Composite
*
* @category Zend
* @package Zend_Soap
* @subpackage Wsdl
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Soap_Wsdl_Strategy_Composite implements Zend_Soap_Wsdl_Strategy_Interface
{
/**
* Typemap of Complex Type => Strategy pairs.
*
* @var array
*/
protected $_typeMap = array();
/**
* Default Strategy of this composite
*
* @var string|Zend_Soap_Wsdl_Strategy_Interface
*/
protected $_defaultStrategy;
/**
* Context WSDL file that this composite serves
*
* @var Zend_Soap_Wsdl|null
*/
protected $_context;
/**
* Construct Composite WSDL Strategy.
*
* @throws Zend_Soap_Wsdl_Exception
* @param array $typeMap
* @param string|Zend_Soap_Wsdl_Strategy_Interface $defaultStrategy
*/
public function __construct(array $typeMap=array(), $defaultStrategy="Zend_Soap_Wsdl_Strategy_DefaultComplexType")
{
foreach($typeMap AS $type => $strategy) {
$this->connectTypeToStrategy($type, $strategy);
}
$this->_defaultStrategy = $defaultStrategy;
}
/**
* Connect a complex type to a given strategy.
*
* @throws Zend_Soap_Wsdl_Exception
* @param string $type
* @param string|Zend_Soap_Wsdl_Strategy_Interface $strategy
* @return Zend_Soap_Wsdl_Strategy_Composite
*/
public function connectTypeToStrategy($type, $strategy)
{
if(!is_string($type)) {
/**
* @see Zend_Soap_Wsdl_Exception
*/
require_once "Zend/Soap/Wsdl/Exception.php";
throw new Zend_Soap_Wsdl_Exception("Invalid type given to Composite Type Map.");
}
$this->_typeMap[$type] = $strategy;
return $this;
}
/**
* Return default strategy of this composite
*
* @throws Zend_Soap_Wsdl_Exception
* @param string $type
* @return Zend_Soap_Wsdl_Strategy_Interface
*/
public function getDefaultStrategy()
{
$strategy = $this->_defaultStrategy;
if(is_string($strategy) && class_exists($strategy)) {
$strategy = new $strategy;
}
if( !($strategy instanceof Zend_Soap_Wsdl_Strategy_Interface) ) {
/**
* @see Zend_Soap_Wsdl_Exception
*/
require_once "Zend/Soap/Wsdl/Exception.php";
throw new Zend_Soap_Wsdl_Exception(
"Default Strategy for Complex Types is not a valid strategy object."
);
}
$this->_defaultStrategy = $strategy;
return $strategy;
}
/**
* Return specific strategy or the default strategy of this type.
*
* @throws Zend_Soap_Wsdl_Exception
* @param string $type
* @return Zend_Soap_Wsdl_Strategy_Interface
*/
public function getStrategyOfType($type)
{
if(isset($this->_typeMap[$type])) {
$strategy = $this->_typeMap[$type];
if(is_string($strategy) && class_exists($strategy)) {
$strategy = new $strategy();
}
if( !($strategy instanceof Zend_Soap_Wsdl_Strategy_Interface) ) {
/**
* @see Zend_Soap_Wsdl_Exception
*/
require_once "Zend/Soap/Wsdl/Exception.php";
throw new Zend_Soap_Wsdl_Exception(
"Strategy for Complex Type '".$type."' is not a valid strategy object."
);
}
$this->_typeMap[$type] = $strategy;
} else {
$strategy = $this->getDefaultStrategy();
}
return $strategy;
}
/**
* Method accepts the current WSDL context file.
*
* @param Zend_Soap_Wsdl $context
*/
public function setContext(Zend_Soap_Wsdl $context)
{
$this->_context = $context;
return $this;
}
/**
* Create a complex type based on a strategy
*
* @throws Zend_Soap_Wsdl_Exception
* @param string $type
* @return string XSD type
*/
public function addComplexType($type)
{
if(!($this->_context instanceof Zend_Soap_Wsdl) ) {
/**
* @see Zend_Soap_Wsdl_Exception
*/
require_once "Zend/Soap/Wsdl/Exception.php";
throw new Zend_Soap_Wsdl_Exception(
"Cannot add complex type '".$type."', no context is set for this composite strategy."
);
}
$strategy = $this->getStrategyOfType($type);
$strategy->setContext($this->_context);
return $strategy->addComplexType($type);
}
}

View file

@ -0,0 +1,83 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @subpackage Wsdl
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DefaultComplexType.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Soap_Wsdl_Strategy_Abstract
*/
require_once "Zend/Soap/Wsdl/Strategy/Abstract.php";
/**
* Zend_Soap_Wsdl_Strategy_DefaultComplexType
*
* @category Zend
* @package Zend_Soap
* @subpackage Wsdl
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Soap_Wsdl_Strategy_DefaultComplexType extends Zend_Soap_Wsdl_Strategy_Abstract
{
/**
* Add a complex type by recursivly using all the class properties fetched via Reflection.
*
* @param string $type Name of the class to be specified
* @return string XSD Type for the given PHP type
*/
public function addComplexType($type)
{
if(!class_exists($type)) {
require_once "Zend/Soap/Wsdl/Exception.php";
throw new Zend_Soap_Wsdl_Exception(sprintf(
"Cannot add a complex type %s that is not an object or where ".
"class could not be found in 'DefaultComplexType' strategy.", $type
));
}
$dom = $this->getContext()->toDomDocument();
$class = new ReflectionClass($type);
$complexType = $dom->createElement('xsd:complexType');
$complexType->setAttribute('name', $type);
$all = $dom->createElement('xsd:all');
foreach ($class->getProperties() as $property) {
if ($property->isPublic() && preg_match_all('/@var\s+([^\s]+)/m', $property->getDocComment(), $matches)) {
/**
* @todo check if 'xsd:element' must be used here (it may not be compatible with using 'complexType'
* node for describing other classes used as attribute types for current class
*/
$element = $dom->createElement('xsd:element');
$element->setAttribute('name', $property->getName());
$element->setAttribute('type', $this->getContext()->getType(trim($matches[1][0])));
$all->appendChild($element);
}
}
$complexType->appendChild($all);
$this->getContext()->getSchema()->appendChild($complexType);
$this->getContext()->addType($type);
return "tns:$type";
}
}

View file

@ -0,0 +1,48 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @subpackage Wsdl
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Interface for Zend_Soap_Wsdl_Strategy.
*
* @category Zend
* @package Zend_Soap
* @subpackage Wsdl
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Soap_Wsdl_Strategy_Interface
{
/**
* Method accepts the current WSDL context file.
*
* @param <type> $context
*/
public function setContext(Zend_Soap_Wsdl $context);
/**
* Create a complex type based on a strategy
*
* @param string $type
* @return string XSD type
*/
public function addComplexType($type);
}