Permalink
Browse files

[UPDATE] behaviour and php doc enhancements

[UPDATE] behaviour and php doc enhancements

Update WsdlToPhpGenerator::manageWsdlNodeDocumentation() method in order
to improve, again, documentation tags detection. Update
WsdlToPhpGenerator php doc comment.

Update WsdlToPhpModel::getCleanName() method behaviour in order to allow
to keep muliple consecutive undescores in the generated name. So the
struct attributes are detected as having a clean name even if they
contain multiple consecutive underscores. Update
WsdlToPhpModel::cleanString() method in order to take account of this
new parameter. By default, multiple consecutive underscores are kept.
Update WsdlToPhpModel php doc comments.

Update WsdlToPhpStruct::getAttributes() calls in
WsdlToPhpFunction::getComment() and WsdlToPhpFunction::getBody() methods
in order to take advantage of the new WsdlToPhpStruct::getAttributes()
method behaviour.

Update WsdlToPhpStruct::getAttributes() behaviour by adding a second
parameter allowing to get attributes ordered as required attributes are
positionned as first attributes. So, the generated class __construct()
method will be easier to call as the required parameters are placed as
first parameters. Improve WsdlToPhpStruct::isArray() method in order to
take account the number of attributes the struct owns by calling new
WsdlToPhpStruct::countOwnAttributes() method. Improve generated array
containing parameters passed to the parent class in order to take
account of the parameter type when parameter is a generated array type
class. Update WsdlToPhpStruct php doc comment.

Update WsdlToPhpStructAttribute::getSetterDeclaration() method in order
to generate better php doc comment for the current attribute setter
method when struct is an array type class. Update
WsdlToPhpStructAttribute php doc comment.

Update WsdlToPhpStructValue::getCleanName() method according to the new
behaviour of WsdlToPhpModel::getCleanName() method. Update
WsdlToPhpStructValue::getDeclaration() to remove useless parameters
passed to the WsdlToPhpStructValue::getCleanName() method call. Update
WsdlToPhpStructValue php doc comment.

Update WsdlToPhpService php doc comment.
  • Loading branch information...
1 parent e58de30 commit dbb6e52c81b057ba292ff5b11a049c7a9c4f93c8 @mikaelcom committed Feb 15, 2013
Showing with 135 additions and 97 deletions.
  1. +5 −4 WsdlToPhpFunction.php
  2. +52 −55 WsdlToPhpGenerator.php
  3. +16 −10 WsdlToPhpModel.php
  4. +1 −1 WsdlToPhpService.php
  5. +50 −10 WsdlToPhpStruct.php
  6. +2 −11 WsdlToPhpStructAttribute.php
  7. +9 −6 WsdlToPhpStructValue.php
View
@@ -80,7 +80,7 @@ public function getComment($_part = '')
$model = self::getModelByName($this->getParameterType());
if($model && $model->getIsStruct() && !$model->getIsRestriction())
{
- $attributes = $model->getAttributes(true);
+ $attributes = $model->getAttributes(true,true);
if(count($attributes))
{
foreach($attributes as $attributeData)
@@ -116,6 +116,7 @@ public function getComment($_part = '')
/**
* Set the function body
* @uses WsdlToPhpModel::getName()
+ * @uses WsdlToPhpModel::getPackagedName()
* @uses WsdlToPhpModel::getModelByName()
* @uses WsdlToPhpModel::getCleanName()
* @uses WsdlToPhpModel::nameIsClean()
@@ -142,7 +143,7 @@ public function getBody(&$_body)
$returnModel = ($returnModel && $returnModel->getIsStruct() && !$returnModel->getIsRestriction())?$returnModel:null;
if($parameterModel)
{
- if(count($parameterModel->getAttributes(true)))
+ if(count($parameterModel->getAttributes(true,true)))
{
$parameterName = '$_' . lcfirst($parameterModel->getPackagedName());
$parameter = $parameterModel->getPackagedName() . ' ' . $parameterName;
@@ -168,7 +169,7 @@ public function getBody(&$_body)
}
else
$parameterName = $parameter = '';
- array_push($_body,'public function ' . self::uniqueName(self::replaceReservedPhpKeyword($this->getCleanName(),$this->getName()),$this->getOwner()->getName()) . '(' . $parameter . ')');
+ array_push($_body,'public function ' . self::uniqueName(self::replaceReservedPhpKeyword($this->getCleanName(),$this->getOwner()->getPackagedName()),$this->getOwner()->getPackagedName()) . '(' . $parameter . ')');
array_push($_body,'{');
array_push($_body,'try');
array_push($_body,'{');
@@ -183,7 +184,7 @@ public function getBody(&$_body)
if($parameterModel)
{
$soapParametersEnd = array();
- $attributes = $parameterModel->getAttributes(true);
+ $attributes = $parameterModel->getAttributes(true,true);
if(count($attributes))
{
foreach($attributes as $attributeData)
View
@@ -263,6 +263,12 @@
* <li>{@link http://portaplusapi.icc-switch.com/soap12}</li>
* </ul>
* </li>
+ * <li>Operations calls own obect parameter methods and inherited methods (php code and php doc must take account of the inheritance) :
+ * <ul>
+ * <li>{@link http://voipnow2demo.4psa.com//soap2/schema/3.0.0/voipnowservice.wsdl}, ex : Add, AddUser, AddServiceProvider</li>
+ * <li>{@link http://www.reservationfactory.com/wsdls/air_v21_0/Air.wsdl}, ex : service</li>
+ * </ul>
+ * </li>
* <li>Biggest Packages generated :
* <ul>
* <li>{@link https://raw.github.com/jkinred/psphere/master/psphere/wsdl/vimService.wsdl}</li>
@@ -2336,70 +2342,61 @@ protected function manageWsdlNodeDocumentation($_wsdlLocation = '',DOMNode $_dom
/**
* Find parent node of this documentation node without taking care of the name attribute for enumeration and definitions
* This case is managed first because enumeration are contained by elements and the method could climb ot its parent without stopping on the enumeration tag
+ * Go from the deepest possible node to the highest possible node
+ * Each case must treated on the same level, this is why we test the suitableParentNode at each case
*/
- $parentNode = self::findSuitableParent($_domNode,false,array(
- 'enumeration',
- 'definitions'));
- $parentNodeManaged = false;
- if($parentNode)
+ $enumerationNode = self::findSuitableParent($_domNode,false,array(
+ 'enumeration'));
+ $definitionsNode = self::findSuitableParent($_domNode,false,array(
+ 'definitions'));
+ $attributeGroupNode = self::findSuitableParent($_domNode,false,array(
+ 'attributeGroup'));
+ $anyNode = self::findSuitableParent($_domNode,true,array(
+ 'operation'));
+ /**
+ * is it an enumeration' value
+ */
+ if($enumerationNode && stripos($enumerationNode->nodeName,'enumeration') !== false)
{
/**
- * is it an enumeration
+ * Find parent node of this enumeration node
*/
- if(stripos($parentNode->nodeName,'enumeration') !== false)
- {
- /**
- * Find parent node of this enumeration node
- */
- $upParentNode = self::findSuitableParent($parentNode);
- if($upParentNode)
- {
- $this->setStructValueDocumentation($upParentNode->getAttribute('name'),$parentNode->getAttribute('value'),$documentation);
- $parentNodeManaged = true;
- }
- }
- /**
- * is it a definitions ?
- */
- elseif(stripos($parentNode->nodeName,'definitions') !== false)
- {
- $this->addWsdlMeta('documentation',$documentation);
- $parentNodeManaged = true;
- }
+ $upParentNode = self::findSuitableParent($enumerationNode);
+ if($upParentNode)
+ $this->setStructValueDocumentation($upParentNode->getAttribute('name'),$enumerationNode->getAttribute('value'),$documentation);
}
- if(!$parentNodeManaged)
+ /**
+ * is it an attributeGroup element, nothing yet but need to be catched here
+ */
+ elseif($attributeGroupNode && stripos($attributeGroupNode->nodeName,'attributeGroup') !== false)
+ {}
+ /**
+ * is it an element ? part of a struct
+ */
+ elseif($anyNode && (stripos($anyNode->nodeName,'element') !== false || stripos($anyNode->nodeName,'attribute') !== false) && $anyNode->hasAttribute('type'))
{
/**
- * Find parent node of this documentation node with the name attribute defined
+ * Find parent node of this documentation node
*/
- $parentNode = self::findSuitableParent($_domNode,true,array(
- 'operation'));
- if($parentNode)
- {
- /**
- * is it an element ? part of a struct
- */
- if((stripos($parentNode->nodeName,'element') !== false || stripos($parentNode->nodeName,'attribute') !== false) && $parentNode->hasAttribute('type'))
- {
- /**
- * Find parent node of this documentation node
- */
- $upParentNode = self::findSuitableParent($parentNode);
- if($upParentNode)
- $this->setStructAttributeDocumentation($upParentNode->getAttribute('name'),$parentNode->getAttribute('name'),$documentation);
- }
- /**
- * is it a struct ?
- */
- elseif(stripos($parentNode->nodeName,'element') !== false || stripos($parentNode->nodeName,'complextype') !== false || stripos($parentNode->nodeName,'simpletype') !== false || stripos($parentNode->nodeName,'attribute') !== false)
- $this->setStructDocumentation($parentNode->getAttribute('name'),$documentation);
- /**
- * is it an operation ?
- */
- elseif(stripos($parentNode->nodeName,'operation') !== false)
- $this->setServiceFunctionDocumentation($parentNode->getAttribute('name'),$documentation);
- }
+ $upParentNode = self::findSuitableParent($anyNode);
+ if($upParentNode)
+ $this->setStructAttributeDocumentation($upParentNode->getAttribute('name'),$anyNode->getAttribute('name'),$documentation);
}
+ /**
+ * is it a struct ?
+ */
+ elseif($anyNode && (stripos($anyNode->nodeName,'element') !== false || stripos($anyNode->nodeName,'complextype') !== false || stripos($anyNode->nodeName,'simpletype') !== false || stripos($anyNode->nodeName,'attribute') !== false))
+ $this->setStructDocumentation($anyNode->getAttribute('name'),$documentation);
+ /**
+ * is it an operation ?
+ */
+ elseif($anyNode && stripos($anyNode->nodeName,'operation') !== false)
+ $this->setServiceFunctionDocumentation($anyNode->getAttribute('name'),$documentation);
+ /**
+ * is it the definitions node of the WSDL
+ */
+ elseif($definitionsNode && stripos($definitionsNode->nodeName,'definitions') !== false)
+ $this->addWsdlMeta('documentation',$documentation);
self::audit('managewsdlnode_documentation',!empty($_wsdlLocation)?$_wsdlLocation:$_fromWsdlLocation);
}
/**
View
@@ -316,7 +316,7 @@ public function getDocumentation()
return self::cleanComment($this->getMetaValue(self::META_DOCUMENTATION,''),' ');
}
/**
- * Return a meta value according to its name
+ * Returns a meta value according to its name
* @uses WsdlToPhpModel::getMeta()
* @param string $_metaName the meta information name
* @param string $_fallback the fallback value if unset
@@ -327,7 +327,7 @@ public function getMetaValue($_metaName,$_fallback = null)
return array_key_exists($_metaName,$this->getMeta())?$this->meta[$_metaName]:$_fallback;
}
/**
- * Return the value of the first meta value assigned to the name
+ * Returns the value of the first meta value assigned to the name
* @param array $_names the meta names to check
* @param string $_fallback the fallback value if anyone is set
* @return mixed the meta information value
@@ -359,23 +359,26 @@ public function setName($_name)
return ($this->name = $_name);
}
/**
- * Return a valid clean name for PHP
+ * Returns a valid clean name for PHP
* @uses WsdlToPhpModel::getName()
* @uses WsdlToPhpModel::cleanString()
+ * @param bool $_keepMultipleUnderscores optional, allows to keep the multiple consecutive underscores
* @return string
*/
- public function getCleanName()
+ public function getCleanName($_keepMultipleUnderscores = true)
{
- return self::cleanString($this->getName());
+ return self::cleanString($this->getName(),$_keepMultipleUnderscores);
}
/**
+ * Returns the owner model object
* @return WsdlToPhpModel
*/
public function getOwner()
{
return $this->owner;
}
/**
+ * Set the owner model object
* @param WsdlToPhpModel $_owner object the owner of the current model
* @uses WsdlToPhpModel::updateModels()
* @return WsdlToPhpModel
@@ -397,7 +400,7 @@ public function nameIsClean()
return ($this->getName() != '' && $this->getName() == $this->getCleanName());
}
/**
- * Return the packaged name
+ * Returns the packaged name
* @uses WsdlToPhpGenerator::getPackageName()
* @uses WsdlToPhpModel::getCleanName()
* @uses WsdlToPhpModel::getContextualPart()
@@ -428,11 +431,15 @@ public function getDocSubPackages()
/**
* Clean a string to make it valid as PHP variable
* @param string $_string the string to clean
+ * @param bool $_keepMultipleUnderscores optional, allows to keep the multiple consecutive underscores
* @return string
*/
- public static function cleanString($_string)
+ public static function cleanString($_string,$_keepMultipleUnderscores = true)
{
- return preg_replace('/[_]+/','_',preg_replace('/[^a-zA-Z0-9_]/','_',$_string));
+ $cleanedString = preg_replace('/[^a-zA-Z0-9_]/','_',$_string);
+ if(!$_keepMultipleUnderscores)
+ $cleanedString = preg_replace('/[_]+/','_',$cleanedString);
+ return $cleanedString;
}
/**
* Get models
@@ -465,9 +472,8 @@ private static function setModels(array $_models = array())
}
/**
* Update models with model
- * @uses WsdlToPhpModel::getModels()
- * @uses WsdlToPhpModel::setModels()
* @uses WsdlToPhpModel::getName()
+ * @uses WsdlToPhpModel::__toString()
* @param WsdlToPhpModel $_model a WsdlToPhpModel object
* @return WsdlToPhpStruct|bool
*/
View
@@ -48,7 +48,7 @@ public function getDocSubPackages()
'Services');
}
/**
- * Returns the comment lines for this function
+ * Returns the comment lines for this service
* @uses WsdlToPhpModel::getModelByName()
* @uses WsdlToPhpModel::getPackagedName()
* @uses WsdlToPhpService::getFunctions()
Oops, something went wrong.

0 comments on commit dbb6e52

Please sign in to comment.