Permalink
Browse files

[UPDATE] new features and php doc improvement

WsdlClass__construct method allows to reset or not the SoapClient if its
not needed.

New methods are generated within the Services classes in order to set
the SoapHeaders after instancitating the service class. For each
required SoapHeader, a method is available and makes easy to set the
SoapHeader.

Improvement in WsdlToPhpModel::getValueWithinItsType() in order to allow
to indicate in wich type the value should be returned

Update Structs __construct() method when WsdlClass is not generated in
order to call its setters
  • Loading branch information...
1 parent b472434 commit 3449c6d4411db62e2fcc67c5d49ba74618899e0b @mikaelcom committed Apr 4, 2013
Showing with 158 additions and 18 deletions.
  1. +5 −3 WsdlClassFileTpl.php
  2. +31 −7 WsdlToPhpModel.php
  3. +93 −2 WsdlToPhpService.php
  4. +27 −5 WsdlToPhpStruct.php
  5. +2 −1 WsdlToPhpStructAttribute.php
View
8 WsdlClassFileTpl.php
@@ -123,17 +123,19 @@ class PackageNameWsdlClass extends stdClass implements ArrayAccess,Iterator,Coun
* @uses PackageNameWsdlClass::initSoapClient()
* @uses PackageNameWsdlClass::initInternArrayToIterate()
* @uses PackageNameWsdlClass::_set()
- * @param array $_arrayOfValues values
+ * @param array $_arrayOfValues SoapClient options or object attribute values
+ * @param bool $_resetSoapClient allows to disable the SoapClient redefinition
* @return PackageNameWsdlClass
*/
- public function __construct($_arrayOfValues = array())
+ public function __construct($_arrayOfValues = array(),$_resetSoapClient = true)
{
$this->setLastError(array());
/**
* Init soap Client
* Set default values
*/
- $this->initSoapClient($_arrayOfValues);
+ if($_resetSoapClient)
+ $this->initSoapClient($_arrayOfValues);
/**
* Init array of values if set
*/
View
38 WsdlToPhpModel.php
@@ -538,16 +538,40 @@ protected static function uniqueName($_name,$_context)
* @param mixed $_value the value
* @return mixed
*/
- public static function getValueWithinItsType($_value)
- {
- if(is_int($_value))
+ public static function getValueWithinItsType($_value,$_knownType = null)
+ {
+ if(is_int($_value) || in_array($_knownType,array(
+ 'time',
+ 'positiveInteger',
+ 'unsignedLong',
+ 'unsignedInt',
+ 'short',
+ 'long',
+ 'int',
+ 'integer')))
return intval($_value);
- elseif(is_float($_value))
+ elseif(is_float($_value) || in_array($_knownType,array(
+ 'float',
+ 'double',
+ 'decimal')))
return floatval($_value);
- elseif(is_numeric($_value))
+ elseif(is_numeric($_value) || in_array($_knownType,array(
+ 'time',
+ 'positiveInteger',
+ 'unsignedLong',
+ 'unsignedInt',
+ 'short',
+ 'long',
+ 'int',
+ 'integer',
+ 'float',
+ 'double',
+ 'decimal')))
return intval($_value) == $_value?intval($_value):floatval($_value);
- elseif(is_bool($_value))
- return $_value?true:false;
+ elseif(is_bool($_value) || in_array($_knownType,array(
+ 'bool',
+ 'boolean')))
+ return ($_value === 'true' || $_value === true || $_value === 1 || $_value === '1');
else
return $_value;
}
View
95 WsdlToPhpService.php
@@ -51,6 +51,9 @@ public function getDocSubPackages()
* Returns the comment lines for this service
* @uses WsdlToPhpModel::getModelByName()
* @uses WsdlToPhpModel::getPackagedName()
+ * @uses WsdlToPhpModel::getGenericWsdlClassName()
+ * @uses WsdlToPhpModel::getMetaValue()
+ * @uses WsdlToPhpModel::cleanString()
* @uses WsdlToPhpService::getFunctions()
* @uses WsdlToPhpFunction::getReturnType()
* @uses WsdlToPhpFunction::getComment()
@@ -65,11 +68,16 @@ public function getClassBody(&$_body)
if(count($this->getFunctions()))
{
$returnTypes = array();
+ $soapHeaders = array();
foreach($this->getFunctions() as $function)
{
+ $function = $this->getFunction($function->getName());
array_push($_body,array(
'comment'=>$function->getComment()));
$function->getBody($_body);
+ /**
+ * Gather return types
+ */
$model = self::getModelByName($function->getReturnType());
if($model && $model->getIsStruct())
{
@@ -78,7 +86,28 @@ public function getClassBody(&$_body)
}
else
array_push($returnTypes,$function->getReturnType());
+ /**
+ * Gather SoapHeader informations
+ */
+ $soapHeaderNames = $function->getMetaValue('SOAPHeaderNames',array());
+ $soapHeaderTypes = $function->getMetaValue('SOAPHeaderTypes',array());
+ $soapHeaderNameSpace = $function->getMetaValue('SOAPHeaderNamespace','');
+ if(count($soapHeaderNames) && count($soapHeaderNames) == count($soapHeaderTypes))
+ {
+ foreach($soapHeaderNames as $index=>$soapHeaderName)
+ {
+ $soapHeaderType = str_replace('{@link ','',$soapHeaderTypes[$index]);
+ $soapHeaderType = str_replace('}','',$soapHeaderType);
+ $soapHeaders[$soapHeaderName . '-' . $soapHeaderType . '-' . $soapHeaderNameSpace] = array(
+ 'name'=>$soapHeaderName,
+ 'type'=>$soapHeaderType,
+ 'namespace'=>$soapHeaderNameSpace);
+ }
+ }
}
+ /**
+ * Generates the override getResult method
+ */
if(count($returnTypes) && WsdlToPhpGenerator::getOptionGenerateWsdlClassFile())
{
$returnTypes = array_unique($returnTypes);
@@ -88,7 +117,7 @@ public function getClassBody(&$_body)
*/
$comments = array();
array_push($comments,'Returns the result');
- array_push($comments,'@see ' . WsdlToPhpGenerator::getPackageName() . 'WsdlClass::getResult()');
+ array_push($comments,'@see ' . self::getGenericWsdlClassName() . '::getResult()');
array_push($comments,'@return ' . implode('|',$returnTypes));
/**
* getResult() method body
@@ -101,7 +130,69 @@ public function getClassBody(&$_body)
array_push($_body,'}');
unset($comments);
}
- unset($returnTypes);
+ /**
+ * Generates the SoapHeaders setter methods
+ */
+ if(count($soapHeaders))
+ {
+ foreach($soapHeaders as $soapHeader)
+ {
+ $soapHeaderName = $soapHeader['name'];
+ $soapHeaderType = $soapHeader['type'];
+ $soapHeaderNameSpace = $soapHeader['namespace'];
+ $cleanedName = $this->cleanString($soapHeaderName,false);
+ /**
+ * setSoapHeader() method comments
+ */
+ $comments = array();
+ array_push($comments,'Sets the ' . $soapHeaderName . ' SoapHeader param');
+ array_push($comments,'For more inforamtion, please read the online documentation on {@link http://www.php.net/manual/en/class.soapheader.php}');
+ if(WsdlToPhpGenerator::getOptionGenerateWsdlClassFile())
+ array_push($comments,'@uses ' . self::getGenericWsdlClassName() . '::getSoapClient()');
+ array_push($comments,'@uses SoapClient::__setSoapheaders()');
+ array_push($comments,'@param ' . $soapHeaderType . ' $_' . lcfirst($soapHeaderType));
+ array_push($comments,'@param string $_nameSpace default = ' . $soapHeaderNameSpace);
+ array_push($comments,'@param bool $_mustUnderstand');
+ array_push($comments,'@param string $_actor');
+ array_push($comments,'@return bool true|false');
+ /**
+ * getResult() method body
+ */
+ array_push($_body,array(
+ 'comment'=>$comments));
+ array_push($_body,'public function setSoapHeader' . $cleanedName . '(' . (strpos($soapHeaderType,WsdlToPhpGenerator::getPackageName()) === 0?$soapHeaderType . ' ':'') . '$_' . lcfirst($soapHeaderType) . ',$_nameSpace = ' . var_export($soapHeaderNameSpace,true) . ',$_mustUnderstand = false,$_actor = null)');
+ array_push($_body,'{');
+ array_push($_body,'$defaultHeaders = @self::getSoapClient()->__default_headers;');
+ array_push($_body,'if(!is_array($defaultHeaders))');
+ array_push($_body,'{');
+ array_push($_body,'$defaultHeaders = array();');
+ array_push($_body,'}');
+ array_push($_body,'else');
+ array_push($_body,'{');
+ array_push($_body,'foreach($defaultHeaders as $index=>$soapheader)');
+ array_push($_body,'{');
+ array_push($_body,'if($soapheader->name == \'' . $soapHeaderName . '\')');
+ array_push($_body,'{');
+ array_push($_body,'unset($defaultHeaders[$index]);');
+ array_push($_body,'break;');
+ array_push($_body,'}');
+ array_push($_body,'}');
+ array_push($_body,'}');
+ array_push($_body,'if(!empty($_actor))');
+ array_push($_body,'{');
+ array_push($_body,'array_push($defaultHeaders,new SoapHeader($_nameSpace,\'' . $soapHeaderName . '\',$_' . lcfirst($soapHeaderType) . ',$_mustUnderstand,$_actor));');
+ array_push($_body,'}');
+ array_push($_body,'else');
+ array_push($_body,'{');
+ array_push($_body,'array_push($defaultHeaders,new SoapHeader($_nameSpace,\'' . $soapHeaderName . '\',$_' . lcfirst($soapHeaderType) . ',$_mustUnderstand));');
+ array_push($_body,'}');
+ array_push($_body,'self::getSoapClient()->__setSoapheaders(null);');
+ array_push($_body,'return self::getSoapClient()->__setSoapheaders($defaultHeaders);');
+ array_push($_body,'}');
+ unset($comments);
+ }
+ }
+ unset($returnTypes,$soapHeaders);
}
}
/**
View
32 WsdlToPhpStruct.php
@@ -119,13 +119,17 @@ public function getClassBody(&$_body)
*/
$bodyParameters = array();
$bodyParams = array();
+ $bodyUses = array();
$constructParameters = array();
- foreach($this->getAttributes(false,true) as $attribute)
+ $attributes = $this->getAttributes(false,true);
+ foreach($attributes as $attribute)
{
array_push($_body,array(
'comment'=>$attribute->getComment()));
array_push($_body,$attribute->getDeclaration());
array_push($bodyParameters,'$_' . lcfirst($attribute->getCleanName()) . (!$attribute->isRequired()?' = ' . var_export($attribute->getDefaultValue(),true):''));
+ if(!WsdlToPhpGenerator::getOptionGenerateWsdlClassFile())
+ array_push($bodyUses,$this->getPackagedName() . '::' . $attribute->getSetterName() . '()');
$model = self::getModelByName($attribute->getType());
if($model)
{
@@ -156,9 +160,15 @@ public function getClassBody(&$_body)
*/
$comments = array();
array_push($comments,'Constructor method for ' . $this->getCleanName());
- array_push($comments,'@see parent::__construct()');
- foreach($bodyParams as $_bodyParam)
- array_push($comments,'@param ' . $_bodyParam);
+ /**
+ * Uses the parent constructor method
+ */
+ if(WsdlToPhpGenerator::getOptionGenerateWsdlClassFile())
+ array_push($comments,'@see parent::__construct()');
+ foreach($bodyUses as $bodyUse)
+ array_push($comments,'@uses ' . $bodyUse);
+ foreach($bodyParams as $bodyParam)
+ array_push($comments,'@param ' . $bodyParam);
array_push($comments,'@return ' . $this->getPackagedName());
array_push($_body,array(
'comment'=>$comments));
@@ -168,7 +178,19 @@ public function getClassBody(&$_body)
array_push($_body,'public function __construct(' . implode(',',$bodyParameters) . ')');
array_push($_body,'{');
$model = self::getModelByName($this->getInheritance());
- array_push($_body,(($model && $model->getIsStruct() && WsdlToPhpGenerator::getOptionGenerateWsdlClassFile())?self::getGenericWsdlClassName():'parent') . '::__construct(array(' . implode(',',$constructParameters) . '));');
+ /**
+ * Uses the parent constructor method
+ */
+ if(WsdlToPhpGenerator::getOptionGenerateWsdlClassFile())
+ array_push($_body,(($model && $model->getIsStruct())?self::getGenericWsdlClassName():'parent') . '::__construct(array(' . implode(',',$constructParameters) . '));');
+ /**
+ * Uses its own setters
+ */
+ else
+ {
+ foreach($attributes as $attribute)
+ array_push($_body,'$this->' . $attribute->getSetterName() . '($_' . lcfirst($attribute->getCleanName()) . ');');
+ }
array_push($_body,'}');
/**
* Setters and getters
View
3 WsdlToPhpStructAttribute.php
@@ -262,6 +262,7 @@ public function setType($_type)
* Return potential default value
* @uses WsdlToPhpModel::getMetaValueFirstSet()
* @uses WsdlToPhpModel::getValueWithinItsType()
+ * @uses WsdlToPhpStructAttribute::getType()
* @return mixed
*/
public function getDefaultValue()
@@ -271,7 +272,7 @@ public function getDefaultValue()
'Default',
'DefaultValue',
'defaultValue',
- 'defaultvalue')));
+ 'defaultvalue')),$this->getType());
}
/**
* Return true or false depending on minOccurs information associated to the attribute

0 comments on commit 3449c6d

Please sign in to comment.