ezcWorkflowDefinitionStorageXml::xmlToVariable PHP Method

xmlToVariable() public static method

"Convert" an DOMElement object into a PHP variable.
public static xmlToVariable ( DOMElement $element ) : mixed
$element DOMElement
return mixed
    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;
    }

Usage Example

Exemplo n.º 1
0
Arquivo: set.php Projeto: bmdevel/ezc
 /**
  * Generate node configuration from XML representation.
  *
  * @param DOMElement $element
  * @return array
  * @ignore
  */
 public static function configurationFromXML(DOMElement $element)
 {
     $configuration = array();
     foreach ($element->getElementsByTagName('variable') as $variable) {
         $configuration[$variable->getAttribute('name')] = ezcWorkflowDefinitionStorageXml::xmlToVariable(ezcWorkflowUtil::getChildNode($variable));
     }
     return $configuration;
 }
All Usage Examples Of ezcWorkflowDefinitionStorageXml::xmlToVariable