public static function xmlToVariable(DOMElement $element)
{
$variable = null;
switch ($element->tagName) {
case 'array':
$variable = array();
foreach ($element->getElementsByTagName('element') as $element) {
$value = self::xmlToVariable(ezcWorkflowUtil::getChildNode($element));
if ($element->hasAttribute('key')) {
$variable[(string) $element->getAttribute('key')] = $value;
} else {
$variable[] = $value;
}
}
break;
case 'object':
$className = $element->getAttribute('class');
if ($element->hasChildNodes()) {
$arguments = ezcWorkflowUtil::getChildNodes(ezcWorkflowUtil::getChildNode($element));
$constructorArgs = array();
foreach ($arguments as $argument) {
if ($argument instanceof DOMElement) {
$constructorArgs[] = self::xmlToVariable($argument);
}
}
$class = new ReflectionClass($className);
$variable = $class->newInstanceArgs($constructorArgs);
} else {
$variable = new $className();
}
break;
case 'boolean':
$variable = $element->nodeValue == 'true' ? true : false;
break;
case 'integer':
case 'double':
case 'string':
$variable = $element->nodeValue;
settype($variable, $element->tagName);
}
return $variable;
}