summaryrefslogtreecommitdiff
path: root/framework/3rdParty/WsdlGen
diff options
context:
space:
mode:
Diffstat (limited to 'framework/3rdParty/WsdlGen')
-rw-r--r--framework/3rdParty/WsdlGen/Wsdl.php102
-rw-r--r--framework/3rdParty/WsdlGen/WsdlGenerator.php97
2 files changed, 99 insertions, 100 deletions
diff --git a/framework/3rdParty/WsdlGen/Wsdl.php b/framework/3rdParty/WsdlGen/Wsdl.php
index dcccc5cd..55694438 100644
--- a/framework/3rdParty/WsdlGen/Wsdl.php
+++ b/framework/3rdParty/WsdlGen/Wsdl.php
@@ -16,7 +16,7 @@
*/
/**
- * Contains the dom object used to build up the wsdl. The
+ * Contains the dom object used to build up the wsdl. The
* operations generated by the generator are stored in here until the getWsdl()
* method is called which builds and returns the generated XML string.
* @author Marcus Nyeholt <tanus@users.sourceforge.net>
@@ -29,51 +29,51 @@ class Wsdl
* @var string
*/
private $serviceName;
-
+
/**
* The URI to find the service at. If empty, the current
* uri will be used (minus any query string)
*/
private $serviceUri;
-
+
/**
* The complex types declarations
* @var ArrayObject
*/
private $types;
-
-
+
+
/**
* A collection of SOAP operations
- * @var ArrayObject
+ * @var array
*/
- private $operations;
-
+ private $operations=array();
+
/**
* Wsdl DOMDocument that's generated.
*/
private $wsdl = null;
-
+
/**
* The definitions created for the WSDL
*/
private $definitions = null;
-
+
/**
* The target namespace variable?
*/
private $targetNamespace ='';
-
+
/**
* The binding style (default at the moment)
*/
private $bindingStyle = 'rpc';
-
+
/**
* The binding uri
*/
private $bindingTransport = 'http://schemas.xmlsoap.org/soap/http';
-
+
/**
* Creates a new Wsdl thing
* @param string $name the name of the service.
@@ -87,13 +87,13 @@ class Wsdl
$this->types = new ArrayObject();
$this->targetNamespace = 'urn:'.$name.'wsdl';
}
-
+
public function getWsdl()
{
$this->buildWsdl();
return $this->wsdl;
}
-
+
/**
* Generates the WSDL file into the $this->wsdl variable
*/
@@ -105,37 +105,37 @@ class Wsdl
xmlns:tns="'.$this->targetNamespace.'"
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/"></definitions>';
+ xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/"></definitions>';
$dom = DOMDocument::loadXml($xml);
$this->definitions = $dom->documentElement;
-
+
$this->addTypes($dom);
-
+
$this->addMessages($dom);
$this->addPortTypes($dom);
$this->addBindings($dom);
$this->addService($dom);
-
+
$this->wsdl = $dom->saveXML();
}
-
+
/**
* Adds complexType definitions to the document
* @param DomDocument $dom The document to add to
*/
public function addTypes(DomDocument $dom)
{
- if (!count($this->types)) return;
- $types = $dom->createElement('types');
+ if (!count($this->types)) return;
+ $types = $dom->createElement('types');
$schema = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:schema');
$schema->setAttribute('targetNamespace', $this->targetNamespace);
- foreach($this->types as $type => $elements)
+ foreach($this->types as $type => $elements)
{
$complexType = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
- $complexType->setAttribute('name', $type);
+ $complexType->setAttribute('name', $type);
if(substr($type, strlen($type) - 5, 5) == 'Array') // if it's an array
- {
+ {
$complexContent = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexContent');
$restriction = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
$restriction->setAttribute('base', 'SOAP-ENC:Array');
@@ -144,27 +144,27 @@ class Wsdl
$attribute->setAttribute('arrayType', 'tns:' . substr($type, 0, strlen($type) - 5) . '[]');
$restriction->appendChild($attribute);
$complexContent->appendChild($restriction);
- $complexType->appendChild($complexContent);
- }
- else
+ $complexType->appendChild($complexContent);
+ }
+ else
{
$all = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:all');
- foreach($elements as $elem)
+ foreach($elements as $elem)
{
$e = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
- $e->setAttribute('name', $elem['name']);
+ $e->setAttribute('name', $elem['name']);
$e->setAttribute('type', $elem['type']);
- $all->appendChild($e);
+ $all->appendChild($e);
}
$complexType->appendChild($all);
- }
+ }
$schema->appendChild($complexType);
- $types->appendChild($schema);
+ $types->appendChild($schema);
}
-
+
$this->definitions->appendChild($types);
}
-
+
/**
* Add messages for the service
* @param DomDocument $dom The document to add to
@@ -175,7 +175,7 @@ class Wsdl
$operation->setMessageElements($this->definitions, $dom);
}
}
-
+
/**
* Add the port types for the service
* @param DomDocument $dom The document to add to
@@ -184,14 +184,14 @@ class Wsdl
{
$portType = $dom->createElement('portType');
$portType->setAttribute('name', $this->serviceName.'PortType');
-
+
$this->definitions->appendChild($portType);
foreach ($this->operations as $operation) {
$portOperation = $operation->getPortOperation($dom);
$portType->appendChild($portOperation);
}
}
-
+
/**
* Add the bindings for the service
* @param DomDocument $dom The document to add to
@@ -201,20 +201,20 @@ class Wsdl
$binding = $dom->createElement('binding');
$binding->setAttribute('name', $this->serviceName.'Binding');
$binding->setAttribute('type', 'tns:'.$this->serviceName.'PortType');
-
+
$soapBinding = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/soap/', 'soap:binding');
$soapBinding->setAttribute('style', $this->bindingStyle);
$soapBinding->setAttribute('transport', $this->bindingTransport);
$binding->appendChild($soapBinding);
-
+
$this->definitions->appendChild($binding);
-
+
foreach ($this->operations as $operation) {
$bindingOperation = $operation->getBindingOperation($dom, $this->targetNamespace, $this->bindingStyle);
$binding->appendChild($bindingOperation);
}
}
-
+
/**
* Add the service definition
* @param DomDocument $dom The document to add to
@@ -223,20 +223,20 @@ class Wsdl
{
$service = $dom->createElement('service');
$service->setAttribute('name', $this->serviceName.'Service');
-
+
$port = $dom->createElement('port');
$port->setAttribute('name', $this->serviceName.'Port');
$port->setAttribute('binding', 'tns:'.$this->serviceName.'Binding');
-
+
$soapAddress = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/soap/', 'soap:address');
$soapAddress->setAttribute('location', $this->serviceUri);
$port->appendChild($soapAddress);
-
+
$service->appendChild($port);
-
- $this->definitions->appendChild($service);
+
+ $this->definitions->appendChild($service);
}
-
+
/**
* Adds an operation to have port types and bindings output
* @param WsdlOperation $operation The operation to add
@@ -245,15 +245,15 @@ class Wsdl
{
$this->operations[] = $operation;
}
-
+
/**
* Adds complexTypes to the wsdl
* @param string $type Name of the type
- * @param Array $elements Elements of the type (each one is an associative array('name','type'))
+ * @param Array $elements Elements of the type (each one is an associative array('name','type'))
*/
public function addComplexType($type, $elements)
{
- $this->types[$type] = $elements;
+ $this->types[$type] = $elements;
}
}
?> \ No newline at end of file
diff --git a/framework/3rdParty/WsdlGen/WsdlGenerator.php b/framework/3rdParty/WsdlGen/WsdlGenerator.php
index 3d788769..b7ab544d 100644
--- a/framework/3rdParty/WsdlGen/WsdlGenerator.php
+++ b/framework/3rdParty/WsdlGen/WsdlGenerator.php
@@ -20,7 +20,7 @@ require_once(dirname(__FILE__).'/WsdlMessage.php');
require_once(dirname(__FILE__).'/WsdlOperation.php');
/**
- * Generator for the wsdl.
+ * Generator for the wsdl.
* Special thanks to Cristian Losada for implementing the Complex Types section of the WSDL.
* @author Marcus Nyeholt <tanus@users.sourceforge.net>
* @author Cristian Losada <cristian@teaxul.com>
@@ -33,37 +33,37 @@ class WsdlGenerator
* var WsdlGenerator
*/
private static $instance;
-
+
/**
* The name of this service (the classname)
* @var string
*/
private $serviceName = '';
-
+
/**
* The complex types to use in the wsdl
* @var Array
*/
private $types = array();
-
+
/**
* The operations available in this wsdl
* @var ArrayObject
*/
private $operations;
-
+
/**
* The wsdl object.
* @var object
*/
private $wsdlDocument;
-
+
/**
* The actual wsdl string
* @var string
*/
private $wsdl = '';
-
+
/**
* The singleton instance for the generator
*/
@@ -74,7 +74,7 @@ class WsdlGenerator
}
return self::$instance;
}
-
+
/**
* Get the Wsdl generated
* @return string The Wsdl for this wsdl
@@ -83,10 +83,10 @@ class WsdlGenerator
{
return $this->wsdl;
}
-
+
/**
* Generates WSDL for a passed in class, and saves it in the current object. The
- * WSDL can then be retrieved by calling
+ * WSDL can then be retrieved by calling
* @param string $className The name of the class to generate for
* @param string $serviceUri The URI of the service that handles this WSDL
* @return void
@@ -94,24 +94,24 @@ class WsdlGenerator
public function generateWsdl($className, $serviceUri='')
{
$this->wsdlDocument = new Wsdl($className, $serviceUri);
-
- $classReflect = new ReflectionClass($className);
+
+ $classReflect = new ReflectionClass($className);
$methods = $classReflect->getMethods();
-
+
foreach ($methods as $method) {
// Only process public methods
if ($method->isPublic()) {
$this->processMethod($method);
}
}
-
+
foreach($this->types as $type => $elements) {
$this->wsdlDocument->addComplexType($type, $elements);
}
-
+
$this->wsdl = $this->wsdlDocument->getWsdl();
}
-
+
/**
* Static method that generates and outputs the generated wsdl
* @param string $className The name of the class to export
@@ -120,13 +120,13 @@ class WsdlGenerator
public static function generate($className, $serviceUri='')
{
$generator = WsdlGenerator::getInstance();
- $generator->generateWsdl($className, $serviceUri);
+ $generator->generateWsdl($className, $serviceUri);
//header('Content-type: text/xml');
return $generator->getWsdl();
//exit();
-
+
}
-
+
/**
* Process a method found in the passed in class.
* @param ReflectionMethod $method The method to process
@@ -134,7 +134,6 @@ class WsdlGenerator
protected function processMethod(ReflectionMethod $method)
{
$comment = $method->getDocComment();
-
if (strpos($comment, '@soapmethod') === false) {
return;
}
@@ -147,25 +146,25 @@ class WsdlGenerator
$comment = str_replace("\r", "", $comment);
$comment = preg_replace("/([\\t])+/", "\t", $comment);
$commentLines = explode("\n", $comment);
-
+
$methodDoc = '';
$params = array();
$return = array();
$gotDesc = false;
$gotParams = false;
-
+
foreach ($commentLines as $line) {
if ($line == '') continue;
if ($line{0} == '@') {
$gotDesc = true;
if (preg_match('/^@param\s+([\w\[\]()]+)\s+\$([\w()]+)\s*(.*)/i', $line, $match)) {
$param = array();
- $param['type'] = $this->convertType($match[1]);
+ $param['type'] = $this->convertType($match[1]);
$param['name'] = $match[2];
- $param['desc'] = $match[3];
+ $param['desc'] = $match[3];
$params[] = $param;
}
- else if (preg_match('/^@return\s+([\w\[\]()]+)\s*(.*)/i', $line, $match)) {
+ else if (preg_match('/^@return\s+([\w\[\]()]+)\s*(.*)/i', $line, $match)) {
$gotParams = true;
$return['type'] = $this->convertType($match[1]);
$return['desc'] = $match[2];
@@ -185,19 +184,19 @@ class WsdlGenerator
}
}
}
-
+
$methodName = $method->getName();
$operation = new WsdlOperation($methodName, $methodDoc);
-
+
$operation->setInputMessage(new WsdlMessage($methodName.'Request', $params));
$operation->setOutputMessage(new WsdlMessage($methodName.'Response', array($return)));
-
+
$this->wsdlDocument->addOperation($operation);
-
+
}
-
+
/**
- * Converts from a PHP type into a WSDL type. This is borrowed from
+ * Converts from a PHP type into a WSDL type. This is borrowed from
* Cerebral Cortex (let me know and I'll remove asap).
*
* TODO: date and dateTime
@@ -234,55 +233,55 @@ class WsdlGenerator
break;
case 'void':
return '';
- default:
+ default:
if(strpos($type, '[]')) // if it is an array
- {
+ {
$className = substr($type, 0, strlen($type) - 2);
$type = $className . 'Array';
$this->types[$type] = '';
$this->convertType($className);
- }
- else
+ }
+ else
{
- if(!isset($this->types[$type]))
+ if(!isset($this->types[$type]))
$this->extractClassProperties($type);
- }
- return 'tns:' . $type;
+ }
+ return 'tns:' . $type;
}
}
-
+
/**
* Extract the type and the name of all properties of the $className class and saves it in the $types array
* This method extract properties from PHPDoc formatted comments for variables. Unfortunately the reflectionproperty
* class doesn't have a getDocComment method to extract comments about it, so we have to extract the information
* about the variables manually. Thanks heaps to Cristian Losada for implementing this.
- * @param string $className The name of the class
+ * @param string $className The name of the class
*/
- private function extractClassProperties($className)
+ private function extractClassProperties($className)
{
// Lets get the class' file so we can read the full contents of it.
$classReflect = new ReflectionClass($className);
-
+
if (!file_exists($classReflect->getFileName())) {
throw new Exception('Could not find class file for '.$className);
}
-
+
$file = file_get_contents($classReflect->getFileName());
if ($file == '') {
throw new Exception("File {$classReflect->getFileName()} could not be opened");
}
-
+
$pos = strpos($file, 'class ' . $className);
$pos = strpos($file, '@var', $pos) + 5;
- for($t = 0; $pos > 5; $t++)
- {
+ for($t = 0; $pos > 5; $t++)
+ {
$type = $this->convertType(substr($file, $pos, strpos($file, ' ', $pos) - $pos));
$pos = strpos($file, '$', $pos) + 1;
- $name = substr($file, $pos, strpos($file, ';', $pos) - $pos);
- $this->types[$className][$t] = array('type' => $type, 'name' => $name);
+ $name = substr($file, $pos, strpos($file, ';', $pos) - $pos);
+ $this->types[$className][$t] = array('type' => $type, 'name' => $name);
$pos = strpos($file, '@var', $pos) + 5;
}
}
-
+
}
?> \ No newline at end of file