Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions classes/BaseWsdlWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,21 @@ private function addType(WsdlType &$wsdlType)
$wsdlSequence = $this->createElement("sequence");

// Create WSDL Elements
/* @var $elements WsdlProperty[] */
$elements = $wsdlType->getElements();
foreach ($elements as &$element) {
/* @var $element WsdlProperty */
$wsdlElement = $this->createElement("element");
$wsdlElement->setAttribute("name", $element->name);
if (WsdlType::isPrimitiveType($element->type)) {
$wsdlElement->setAttribute("type", "xsd:" . $element->type);
} else {
$wsdlElement->setAttribute("type", "tns:" . $element->type);
}

if($element->usage && $element->usage=='optional'){
$wsdlElement->setAttribute("minOccurs", "0");
}

// Add WSDL Element to the Sequence
$wsdlSequence->appendChild($wsdlElement);
}
Expand Down Expand Up @@ -268,8 +273,8 @@ private function addBindingOperation($operation)
$binding = $this->getBinding();

$definition = $this->getDefinitionName();
$soapAction = "urn:{$definition}#{$definition}Server#{$operation->name}";

$soapAction = $this->getWsdlDefinition()->getNameSpace()."{$operation->name}";
// Create a new WSDL Operation
$wsdlOperation = $this->createElement("operation");
$wsdlOperation->setAttribute("name", $operation->name);
Expand Down Expand Up @@ -583,9 +588,12 @@ public function getDefinitionName()
*/
public function getClassName()
{
$className = $this->getWsdlDefinition()->getClassFileName();
$className = basename($className, ".inc");
$className = basename($className, ".php");
$className = $this->getWsdlDefinition()->getClassName();
if(!$className){
$className = $this->getWsdlDefinition()->getClassFileName();
$className = basename($className, ".inc");
$className = basename($className, ".php");
}

return $className;
}
Expand Down
43 changes: 28 additions & 15 deletions classes/DocBlockParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class DocBlockParser

private static $docBlockTags = array(
"@param" => array(
"regex" => "|@param\s+([a-zA-Z0-9\[\]]+)\s+\\\$([a-zA-Z0-9]+)\s+(.*)|",
"matches" => array("type", "name", "desc")
"regex" => "#@param\s+([_a-zA-Z0-9\[\]]+)\s+\\\$([_a-zA-Z0-9]+)(\=null|)\s+(.*)#",
"matches" => array("type", "name", "optional", "desc")
),
"@return" => array(
"regex" => "|@return\s+([a-zA-Z0-9\[\]]+)\s+(.*)|",
"regex" => "|@return\s+([_a-zA-Z0-9\[\]]+)\s+(.*)|",
"matches" => array("type", "desc")
),
"@author" => array(
Expand All @@ -37,27 +37,40 @@ class DocBlockParser
"regex" => "|@internal\s+(.*)|",
"matches" => array("usage")
),
"@var" => array(
"regex" => "|@var\s+([_a-zA-Z0-9\[\]]+)\s+(.*)|",
"matches" => array("type", "desc")
)
);

/**
* Get the Type and Description Information for a Property
*
* @param string $name The name of the Property
* @param string $className the name file which contains
* the Class that the property is defined
* @param ReflectionProperty $property The reflected property
*/
public static function getPropertyInfo(ReflectionProperty $property)
{
$info = array();
$commentLine = $property->getDocComment();

if (strlen($commentLine)) {
if (preg_match("|/\*\*\s+@var\s+([a-zA-Z0-9\[\]]+)([^(\*/)]*)\*/|", $commentLine, $matches)) {
$info['type'] = $matches[1];
if (isset($matches[2])) {
$info['desc'] = $matches[2];
// parse docblock
$taginfoarr=self::getTagInfo($commentLine);
$info=array();
// flatten the parsed data
foreach($taginfoarr as $taginfo){
foreach($taginfo as $tag => $tagdata){
foreach($tagdata as $key => $value){
if($value){
// trim value because it can contain newlines etc
$info[$key]=trim($value);
}
}
return $info;
}
}
// if we found the type, return
if(isset($info['type'])){
return $info;
}
}
return null;
Expand All @@ -72,7 +85,7 @@ public static function getPropertyInfo(ReflectionProperty $property)
public static function getDescription($doc)
{
$tagRegex = self::getTagRegex();
$lines = split("\n", self::stripCommentChars($doc));
$lines = explode("\n", self::stripCommentChars($doc));
$desc = "";

foreach ($lines as $line) {
Expand Down Expand Up @@ -101,8 +114,8 @@ public static function getTagInfo($doc)
$currentTag = null;

// Do a Line at a time
$lines = split("\n", self::stripCommentChars($doc));

$lines = explode("\n", self::stripCommentChars($doc));
for ($i = 0, $c = count($lines); $i < $c; $i++) {

// Loop through the Doc Tag list and Find Matches
Expand Down Expand Up @@ -156,7 +169,7 @@ public static function getTagInfo($doc)
private static function stripCommentChars($doc)
{
$out = "";
$lines = split("\n", $doc);
$lines = explode("\n", $doc);
foreach ($lines as $line) {
$line = preg_replace("|^\s*/\**|", "", $line);
$line = preg_replace("|^\s*\**|", "", $line);
Expand Down
50 changes: 48 additions & 2 deletions classes/WsdlDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class WsdlDefinition
/** @var string */
private $classFileName;

/** @var string */
private $className;


/** @var string */
private $wsdlFileName;

Expand All @@ -46,8 +49,10 @@ class WsdlDefinition
/** @var string */
private $baseUrl;



/** @var string[] */
private $typeMapping = array();


/**
* Get the value of classFileName
*
Expand All @@ -58,6 +63,26 @@ public function getClassFileName()
return $this->classFileName;
}

/**
* Set the value of className
*
* @param string $className The value of className
*/
public function setClassName($className)
{
$this->className = $className;
}

/**
* Get the value of className
*
* @return string The value of className
*/
public function getClassName()
{
return $this->className;
}

/**
* Set the value of classFileName
*
Expand Down Expand Up @@ -174,4 +199,25 @@ public function setBaseUrl($baseUrl)
$this->baseUrl = $baseUrl;
}


/**
* Get the value of typeMapping
*
* @return string[] The typeMapping as assoc array
*/
public function getTypeMapping()
{
return $this->typeMapping;
}

/**
* Set the value of typeMapping
*
* @param string[] $mapping The value of typeMapping
*/
public function setTypeMapping($mapping)
{
$this->typeMapping = $mapping;
}

}
36 changes: 35 additions & 1 deletion classes/WsdlMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

require_once("WsdlPart.php");
require_once("WsdlType.php");

/**
* WSDL Generator for PHP5
Expand All @@ -25,6 +26,8 @@ class WsdlMethod
private $desc = null;
private $header = false;
private $reqHeaders = array();

private $typeMapping = array();

private $params = array();
private $returnType = null;
Expand Down Expand Up @@ -60,6 +63,16 @@ public function setDesc($desc)
$this->desc = $desc;
}

/**
* Set the Description of the Method
*
* @param string[] $mapping Assoc array with type mapping old => new
*/
public function setTypeMappings($mapping)
{
$this->typeMapping = $mapping;
}

/**
* Set whether the Method represents a SOAP Body or Header element
*
Expand Down Expand Up @@ -122,7 +135,17 @@ public function resolveHeaders($wsdlMethods)
public function addParameter($varType, $varName, $varDesc)
{
$param = new StdClass();

if (WsdlType::isArrayTypeClass($varType)) {
$varTypeCheck = WsdlType::stripArrayNotation($varType);
if(array_key_exists($varTypeCheck,$this->typeMapping)){
$varType = $this->typeMapping[$varTypeCheck].'[]';
}
}else{
if(array_key_exists($varType,$this->typeMapping)){
$varType = $this->typeMapping[$varType];
}
}

$param->type = $varType;
$param->name = $varName;
$param->desc = $varDesc;
Expand All @@ -138,6 +161,17 @@ public function addParameter($varType, $varName, $varDesc)
*/
public function setReturn($varType, $varDesc)
{
if (WsdlType::isArrayTypeClass($varType)) {
$varTypeCheck = WsdlType::stripArrayNotation($varType);
if(array_key_exists($varTypeCheck,$this->typeMapping)){
$varType = $this->typeMapping[$varTypeCheck].'[]';
}
}else{
if(array_key_exists($varType,$this->typeMapping)){
$varType = $this->typeMapping[$varType];
}
}

$this->returnType = $varType;
$this->returnDesc = $varDesc;
}
Expand Down
6 changes: 6 additions & 0 deletions classes/WsdlProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class WsdlProperty
public $type = null;
public $name = null;
public $description = null;
public $usage = null;


public function setName($name)
Expand All @@ -45,4 +46,9 @@ public function setDesc($desc)
$this->description = $desc;
}

public function setUsage($usage)
{
$this->usage = $usage;
}

}
Loading