Permalink
Browse files

[UPDATE] adding __set_state() method and enhancements

Add generic WsdlClass::__set_state() method in order to allow
var_export() result to be used. This method is also added to each
generated Struct class.

Ensure that PHP reserved methods are not overridden in WsdlToPhpModel
  • Loading branch information...
mikaelcom committed Apr 23, 2013
1 parent 2dae91c commit 3a8f04c6aee1ee003c3d286efc88f6fb210bcc18
Showing with 54 additions and 2 deletions.
  1. +23 −0 WsdlClassFileTpl.php
  2. +5 −2 WsdlToPhpModel.php
  3. +26 −0 WsdlToPhpStruct.php
@@ -149,6 +149,29 @@ public function __construct($_arrayOfValues = array(),$_resetSoapClient = true)
$this->_set($name,$value);
}
}
/**
* Generic method called when an object has been exported with var_export() functions
* It allows to return an object instantiated with the values
* @uses PackageNameWsdlClass::_set()
* @param array $_array the exported values
* @param string $_className optional (used by inherited classes in order to always call this method)
* @return PackageNameWsdlClass|null
*/
public static function __set_state(array $_array,$_className = __CLASS__)
{
if(class_exists($_className))
{
$object = @new $_className($_array);
if($object)
{
foreach($_array as $name=>$value)
$object->_set($name,$value);
}
return $object;
}
else
return null;
}
/**
* Static method getting current SoapClient
* @return SoapClient
@@ -46,7 +46,7 @@ class WsdlToPhpModel
* Plus {PackageName}WsdlClass specific/common methods
* @var string
*/
private static $phpReserverKeywords = '__construct|getSoapClient|setSoapClient|initSoapClient|setLocation|getDefaultWsdlOptions|getLastRequest|getLastResponse|getFormatedXml|add|getResult|length|count|current|item|offsetGet|offsetSet|key|last|first|next|offsetExists|offsetUnset|rewind|setResult|toSend|valueIsValid|valid|getLastError|setLastError|saveLastError|getLastErrorForMethod|getInternArrayToIterate|setInternArrayToIterate|getInternArrayToIterateOffset|initInternArrayToIterate|setInternArrayToIterateOffset|getInternArrayToIterateIsArray|setInternArrayToIterateIsArray|getAttributeName|__toString|_set|_get|__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|print|private|protected|public|require|require_once|return|static|switch|throw|trait|try|unset|use|var|while|xor';
private static $phpReserverKeywords = '__construct|__destruct|__call|__callStatic|__get|__set|__isset|__unset|__sleep|__wakeup|__toString|__invoke|__set_state|__clone|getSoapClient|setSoapClient|initSoapClient|setLocation|getDefaultWsdlOptions|getLastRequest|getLastResponse|getFormatedXml|add|getResult|length|count|current|item|offsetGet|offsetSet|key|last|first|next|offsetExists|offsetUnset|rewind|setResult|toSend|valueIsValid|valid|getLastError|setLastError|saveLastError|getLastErrorForMethod|getInternArrayToIterate|setInternArrayToIterate|getInternArrayToIterateOffset|initInternArrayToIterate|setInternArrayToIterateOffset|getInternArrayToIterateIsArray|setInternArrayToIterateIsArray|getAttributeName|__toString|_set|_get|__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|print|private|protected|public|require|require_once|return|static|switch|throw|trait|try|unset|use|var|while|xor';
/**
* Replaced keywords time in order to generate unique new keyword
* @var array
@@ -162,7 +162,7 @@ public function getClassDeclaration()
$extends = self::getGenericWsdlClassName();
array_push($class,'class ' . $this->getPackagedName() . (!empty($extends)?' extends ' . $extends:''));
/**
* Class body
* Class body starts here
*/
array_push($class,'{');
/**
@@ -185,6 +185,9 @@ public function getClassDeclaration()
array_push($class,'{');
array_push($class,'return __CLASS__;');
array_push($class,'}');
/**
* Class body ends here
*/
array_push($class,'}');
return $class;
}
@@ -335,6 +335,32 @@ public function getClassBody(&$_body)
}
unset($attribute);
}
/**
* __set_state method override
*/
if(WsdlToPhpGenerator::getOptionGenerateWsdlClassFile())
{
/**
* __set_state() method comments
*/
$comments = array();
array_push($comments,'Method called when an object has been exported with var_export() functions');
array_push($comments,'It allows to return an object instantiated with the values');
array_push($comments,'@see ' . self::getGenericWsdlClassName() . '::__set_state()');
array_push($comments,'@uses ' . self::getGenericWsdlClassName() . '::__set_state()');
array_push($comments,'@param array $_array the exported values');
array_push($comments,'@return ' . $this->getPackagedName());
array_push($_body,array(
'comment'=>$comments));
unset($comments);
/**
* __set_state method body
*/
array_push($_body,'public static function __set_state(array $_array,$_className = __CLASS__)');
array_push($_body,'{');
array_push($_body,'return parent::__set_state($_array,$_className);');
array_push($_body,'}');
}
}
}
/**

0 comments on commit 3a8f04c

Please sign in to comment.