Permalink
Browse files

[UPDATE] enhancements and bug fixes

[UPDATE] enhancements and bug fixes
Add owner feature in order to know the owner of a current struct
attribute/value or the owner of a current function. The owner must be a
WsdlToPhpModel object type.
Ensure case sensitive unique naming of methods (setters, getters and
operations) by using generic WsdltoPhpModel::uniqueName() method.
Sort case sensitively return types in the getResult() method php doc.
Refactoring WsdlTophpStructValue::getCleanName() method fixes #6 Github
issue concerning PHP Warning : Strict Standards: Declaration of
WsdlToPhpStructValue::getCleanName() should be compatible with
WsdlToPhpModel::getCleanName() in WsdlToPhpStructValue.php on line 107
  • Loading branch information...
mikaelcom committed Jan 15, 2013
1 parent a66c597 commit 29b5e4785bdb49c4774b7500a62e3ddd45f3f179
Showing with 135 additions and 26 deletions.
  1. +7 −2 WsdlToPhpFunction.php
  2. +5 −1 WsdlToPhpGenerator.php
  3. +48 −2 WsdlToPhpModel.php
  4. +2 −1 WsdlToPhpService.php
  5. +10 −9 WsdlToPhpStruct.php
  6. +20 −5 WsdlToPhpStructAttribute.php
  7. +43 −6 WsdlToPhpStructValue.php
@@ -26,16 +26,19 @@ class WsdlToPhpFunction extends WsdlToPhpModel
* @see WsdlToPhpModel::__construct()
* @uses WsdlToPhpFunction::setParameterType()
* @uses WsdlToPhpFunction::setReturnType()
* @uses WsdlToPhpModel::setOwner()
* @param string $_name the function name
* @param string $_parameterType the type/name of the parameter
* @param string $_returnType the type/name of the return value
* @param WsdlToPhpService $_wsdlToPhpService defines the struct which owns this value
* @return WsdlToPhpFunction
*/
public function __construct($_name,$_parameterType,$_returnType)
public function __construct($_name,$_parameterType,$_returnType,WsdlToPhpService $_wsdlToPhpService)
{
parent::__construct($_name);
$this->setParameterType($_parameterType);
$this->setReturnType($_returnType);
$this->setOwner($_wsdlToPhpService);
}
/**
* Returns the commment lines for this function
@@ -117,6 +120,8 @@ public function getComment($_part = '')
* @uses WsdlToPhpModel::getCleanName()
* @uses WsdlToPhpModel::nameIsClean()
* @uses WsdlToPhpModel::cleanString()
* @uses WsdlToPhpModel::uniqueName()
* @uses WsdlToPhpModel::getOwner()
* @uses WsdlToPhpModel::replaceReservedPhpKeyword()
* @uses WsdlToPhpFunction::getParameterType()
* @uses WsdlToPhpStruct::getAttributes()
@@ -163,7 +168,7 @@ public function getBody(&$_body)
}
else
$parameterName = $parameter = '';
array_push($_body,'public function ' . self::replaceReservedPhpKeyword($this->getCleanName(),$this->getName()) . '(' . $parameter . ')');
array_push($_body,'public function ' . self::uniqueName(self::replaceReservedPhpKeyword($this->getCleanName(),$this->getName()),$this->getOwner()->getName()) . '(' . $parameter . ')');
array_push($_body,'{');
array_push($_body,'try');
array_push($_body,'{');
@@ -95,6 +95,9 @@
* - https://gateway2.pagosonline.net/ws/WebServicesClientesUT?wsdl (doInit(), TestServiceGet, TestServiceLeer)
* Operation name with illegal characters :
* - https://raw.github.com/Sn3b/Omniture-API/master/Solution%20Items/OmnitureAdminServices.wsdl (. in the operation name, so __soapCall method is used)
* Struct attributes with same but different case (ProcStat and Procstat) should have distinct method to set and get (getProcStat/setProcStat and getProcstat_1/setProcstat_1) the value.
* The contruct method must also define the key in the associative array with the corresponding method name.
* Plus, the operation/function which use ths attribute must call the distinct method (getProcStat and getProcstat_1). See http://the-echoplex.net/log/php-case-sensitivity
* @package WsdlToPhpGenerator
* @date 19/12/2012
*/
@@ -867,7 +870,8 @@ private function generateClassMap($_rootDirectory)
$filename);
}
/**
* Generate autoload file for all classes
* Generate autoload file for all classes.
* The classes are loaded automatically in order of their dependency regarding their inheritance (defined in WsdlToPhpGenerate::generateStructsClasses() method).
* @uses WsdlToPhpGenerator::getPackageName()
* @uses WsdlToPhpGenerator::populateFile()
* @param string $_rootDirectory the directory
@@ -31,6 +31,11 @@ class WsdlToPhpModel
* @var string
*/
private $inheritance;
/**
* Store the object which owns the current model
* @var WsdlToPhpModel
*/
private $owner;
/**
* Store all the models generated
* @var array
@@ -47,6 +52,11 @@ class WsdlToPhpModel
* @var array
*/
private static $replacedReservedPhpKeywords = array();
/**
* Unique name generated in order to ensure unique naming (for struct constructor and setters/getters even for different case attribute name whith same value)
* @var array
*/
private static $uniqueNames = array();
/**
* Main constructor
* @uses WsdlToPhpModel::setInheritance()
@@ -235,7 +245,7 @@ public function getMeta()
/**
* Set the meta
* @param array $_meta
* @return array
* @return array
*/
public function setMeta(array $_meta = array())
{
@@ -340,6 +350,21 @@ public function getCleanName()
{
return self::cleanString($this->getName());
}
/**
* @return WsdlToPhpModel
*/
public function getOwner()
{
return $this->owner;
}
/**
* @param WsdlToPhpModel $_owner object the owner of the current model
* @return WsdlToPhpModel
*/
public function setOwner(WsdlToPhpModel $_owner)
{
return ($this->owner = $_owner);
}
/**
* Returns true if the original name is safe to use as a PHP property, variable name or class name
* @uses WsdlToPhpModel::getName()
@@ -459,6 +484,27 @@ public static function replaceReservedPhpKeyword($_keyword,$_context)
else
return $_keyword;
}
/**
* Static method wich returns a unique name case sensitively
* Useful to name methods case sensitively distinct, see http://the-echoplex.net/log/php-case-sensitivity
* @param string $_name the original name
* @param string $_structName the name of owner
* @return string
*/
protected static function uniqueName($_name,$_ownerName)
{
$insensitiveKey = strtolower($_name . '_' . $_ownerName);
$sensitiveKey = $_name . '_' . $_ownerName;
if(array_key_exists($sensitiveKey,self::$uniqueNames))
return self::$uniqueNames[$sensitiveKey];
elseif(!array_key_exists($insensitiveKey,self::$uniqueNames))
self::$uniqueNames[$insensitiveKey] = 0;
else
self::$uniqueNames[$insensitiveKey]++;
$uniqueName = $_name . (self::$uniqueNames[$insensitiveKey]?'_' . self::$uniqueNames[$insensitiveKey]:'');
self::$uniqueNames[$sensitiveKey] = $uniqueName;
return $uniqueName;
}
/**
* Return the value with good type
* @param mixed
@@ -471,7 +517,7 @@ public static function getValueWithinItsType($_value)
elseif(is_float($_value))
return floatval($_value);
elseif(is_numeric($_value))
return intval($_value) === $_value?intval($_value):floatval($_value);
return intval($_value) == $_value?intval($_value):floatval($_value);
elseif(is_bool($_value))
return $_value?true:false;
else
@@ -83,6 +83,7 @@ public function getClassBody(&$_body)
if(count($returnTypes) && WsdlToPhpGenerator::getOptionGenerateWsdlClassFile())
{
$returnTypes = array_unique($returnTypes);
natcasesort($returnTypes);
/**
* getResult() method comments
*/
@@ -130,7 +131,7 @@ private function setFunctions(array $_functions = array())
*/
public function addFunction($_functionName,$_functionParameterType,$_functionReturnType)
{
return ($this->functions[$_functionName] = new WsdlToPhpFunction($_functionName,$_functionParameterType,$_functionReturnType));
return ($this->functions[$_functionName] = new WsdlToPhpFunction($_functionName,$_functionParameterType,$_functionReturnType,$this));
}
/**
* Returns the function by its original name
@@ -131,20 +131,20 @@ public function getClassBody(&$_body)
if($model->getIsStruct())
{
if($model->isArray())
array_push($constructParameters,'\'' . $attribute->getCleanName() . '\'=>new ' . $model->getPackagedName() . '($_' . lcfirst($attribute->getCleanName()) . ')');
array_push($constructParameters,'\'' . $attribute->getUniqueName() . '\'=>new ' . $model->getPackagedName() . '($_' . lcfirst($attribute->getCleanName()) . ')');
else
array_push($constructParameters,'\'' . $attribute->getCleanName() . '\'=>$_' . lcfirst($attribute->getCleanName()));
array_push($constructParameters,'\'' . $attribute->getUniqueName() . '\'=>$_' . lcfirst($attribute->getCleanName()));
$paramType = $model->getPackagedName();
}
else
{
array_push($constructParameters,'\'' . $attribute->getCleanName() . '\'=>$_' . lcfirst($attribute->getCleanName()));
array_push($constructParameters,'\'' . $attribute->getUniqueName() . '\'=>$_' . lcfirst($attribute->getCleanName()));
$paramType = $model->getInheritance()?$model->getInheritance():$attribute->getType();
}
}
else
{
array_push($constructParameters,'\'' . $attribute->getCleanName() . '\'=>$_' . lcfirst($attribute->getCleanName()));
array_push($constructParameters,'\'' . $attribute->getUniqueName() . '\'=>$_' . lcfirst($attribute->getCleanName()));
$paramType = $attribute->getType();
}
array_push($bodyParams,$paramType . ' $_' . lcfirst($attribute->getCleanName()));
@@ -384,7 +384,7 @@ public function getAttributes($_includeInheritanceAttributes = false)
/**
* set the attributes of the struct
* @param array
* @return array
* @return array
*/
public function setAttributes(array $_attributes = array())
{
@@ -398,7 +398,7 @@ public function setAttributes(array $_attributes = array())
*/
public function addAttribute($_attributeName,$_attributeType)
{
return ($this->attributes[$_attributeName] = new WsdlToPhpStructAttribute($_attributeName,$_attributeType));
return ($this->attributes[$_attributeName] = new WsdlToPhpStructAttribute($_attributeName,$_attributeType,$this));
}
/**
* Return the attribute by its name, otherwise null
@@ -464,18 +464,19 @@ private function setValues(array $_values = array())
/**
* Add value to values array
* @uses WsdlToPhpStruct::getValue()
* @param mixed $_value the value
* @uses WsdlToPhpStruct::getValues()
* @param mixed $_value the original value
*/
public function addValue($_value)
{
if(!$this->getValue($_value))
array_push($this->values,new WsdlToPhpStructValue($_value));
array_push($this->values,new WsdlToPhpStructValue($_value,count($this->getValues()),$this));
}
/**
* Get the value object for the given value
* @uses WsdlToPhpStruct::getValues()
* @uses WsdlToPhpModel::getName()
* @param string $_value Value name
* @param string $_value Value name
* @return WsdlToPhpStructValue|null
*/
public function getValue($_value)
@@ -20,14 +20,17 @@ class WsdlToPhpStructAttribute extends WsdlToPhpModel
* Main constructor
* @see WsdlToPhpModel::__construct()
* @uses WsdlToPhpStructAttribute::setType()
* @uses WsdlToPhpModel::setOwner()
* @param string $_name the original name
* @param string $_type the type
* @param WsdlToPhpStruct $_wsdlToPhpStruct defines the struct which owns this value
* @return WsdlToPhpStructAttribute
*/
public function __construct($_name,$_type)
public function __construct($_name,$_type,WsdlToPhpStruct $_wsdlToPhpStruct)
{
parent::__construct($_name);
$this->setType($_type);
$this->setOwner($_wsdlToPhpStruct);
}
/**
* Returns the commment lines for this attribute
@@ -65,6 +68,18 @@ public function getComment($_part = '')
array_push($comments,'@var ' . $this->getType());
return $comments;
}
/**
* Method returning the unique name in the current struct (for setters/getters and struct contrusctor array)
* @uses WsdlToPhpModel::getCleanName()
* @uses WsdlToPhpModel::getOwner()
* @uses WsdlToPhpModel::getName()
* @uses WsdlToPhpModel::uniqueName()
* @return string
*/
public function getUniqueName()
{
return self::uniqueName($this->getCleanName(),$this->getOwner()->getName());
}
/**
* Returns the declaration of the attribute
* @see WsdlToPhpModel::getDeclaration()
@@ -77,21 +92,21 @@ public function getDeclaration()
}
/**
* Returns the getter name for this attribute
* @see WsdlToPhpModel::getCleanName()
* @uses WsdlToPhpStructAttribute::getUniqueName()
* @return string
*/
public function getGetterName()
{
return 'get' . ucfirst($this->getCleanName());
return 'get' . ucfirst(self::getUniqueName());
}
/**
* Returns the getter name for this attribute
* @see WsdlToPhpModel::getCleanName()
* @uses WsdlToPhpStructAttribute::getUniqueName()
* @return string
*/
public function getSetterName()
{
return 'set' . ucfirst($this->getCleanName());
return 'set' . ucfirst(self::getUniqueName());
}
/**
* Returns the array of lines to declare the getter
@@ -16,23 +16,45 @@ class WsdlToPhpStructValue extends WsdlToPhpModel
* @var array
*/
private static $uniqueConstants = array();
/**
* The index of the value in the enumeration struct
* @var int
*/
private $index;
/**
* Main constructor
* @see WsdlToPhpModel::__construct()
* @uses WsdlToPhpModel::setOwner()
* @uses WsdlToPhpStructValue::setIndex()
* @param string $_name the original name
* @param string $_index the index of the value in the enumeration struct
* @param WsdlToPhpStruct $_wsdlToPhpStruct defines the struct which owns this value
* @return WsdlToPhpStructValue
*/
public function __construct($_name,$_index,WsdlToPhpStruct $_wsdlToPhpStruct)
{
parent::__construct($_name);
$this->setIndex($_index);
$this->setOwner($_wsdlToPhpStruct);
}
/**
* Method to return the name of the value as constant
* @see WsdlToPhpModel::getCleanName()
* @uses WsdlToPhpModel::getCleanName()
* @uses WsdlToPhpModel::getName()
* @uses WsdlToPhpStructValue::constantSuffix()
* @uses WsdlToPhpStructValue::getIndex()
* @uses WsdlToPhpStructValue::getOwner()
* @uses WsdlToPhpGenerator::getOptionGenericConstantsNames()
* @param string $_structName the name of the struct which the value belongs to
* @param int $_index the index of the constant contained by the struct class
* @return string
*/
public function getCleanName($_structName,$_index = -1)
public function getCleanName()
{
if(WsdlToPhpGenerator::getOptionGenericConstantsNames() && is_numeric($_index) && $_index >= 0)
return 'ENUM_VALUE_' . $_index;
if(WsdlToPhpGenerator::getOptionGenericConstantsNames() && is_numeric($this->getIndex()) && $this->getIndex() >= 0)
return 'ENUM_VALUE_' . $this->getIndex();
else
{
$key = self::constantSuffix($_structName,parent::getCleanName(),$_index);
$key = self::constantSuffix($this->getOwner()->getName(),parent::getCleanName(),$this->getIndex());
return 'VALUE_' . strtoupper(parent::getCleanName()) . ($key?'_' . $key:'');
}
}
@@ -46,6 +68,21 @@ public function getValue()
{
return self::getValueWithinItsType($this->getName());
}
/**
* @return int
*/
public function getIndex()
{
return $this->index;
}
/**
* @param int
* @return int $_index
*/
public function setIndex($_index)
{
return ($this->index = $_index);
}
/**
* Returns the commment lines for this value
* @see WsdlToPhpModel::getComment()

0 comments on commit 29b5e47

Please sign in to comment.