getChildNode() public static method

Wrapper around getChildNodes() that only returns the first node.
public static getChildNode ( DOMNode $node ) : DOMNode
$node DOMNode
return DOMNode
Example #1
0
File: set.php Project: 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;
 }
Example #2
0
 /**
  * Generate node configuration from XML representation.
  *
  * @param DOMElement $element
  * @return array
  * @ignore
  */
 public static function configurationFromXML(DOMElement $element)
 {
     $configuration = array('class' => $element->getAttribute('serviceObjectClass'), 'arguments' => array());
     $childNode = ezcWorkflowUtil::getChildNode($element);
     if ($childNode->tagName == 'arguments') {
         foreach (ezcWorkflowUtil::getChildNodes($childNode) as $argument) {
             $configuration['arguments'][] = ezcWorkflowDefinitionStorageXml::xmlToVariable($argument);
         }
     }
     return $configuration;
 }
Example #3
0
 /**
  * "Convert" an DOMElement object into a PHP variable.
  *
  * @param  DOMElement $element
  * @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;
 }