ezcWorkflowDefinitionStorageXml::variableToXml PHP Method

variableToXml() public static method

"Convert" a PHP variable into an DOMElement object.
public static variableToXml ( mixed $variable, DOMDocument $document ) : DOMElement
$variable mixed
$document DOMDocument
return DOMElement
    public static function variableToXml($variable, DOMDocument $document)
    {
        if (is_array($variable)) {
            $xmlResult = $document->createElement('array');
            foreach ($variable as $key => $value) {
                $element = $document->createElement('element');
                $element->setAttribute('key', $key);
                $element->appendChild(self::variableToXml($value, $document));
                $xmlResult->appendChild($element);
            }
        }
        if (is_object($variable)) {
            $xmlResult = $document->createElement('object');
            $xmlResult->setAttribute('class', get_class($variable));
        }
        if (is_null($variable)) {
            $xmlResult = $document->createElement('null');
        }
        if (is_scalar($variable)) {
            $type = gettype($variable);
            if (is_bool($variable)) {
                $variable = $variable === true ? 'true' : 'false';
            }
            $xmlResult = $document->createElement($type, $variable);
        }
        return $xmlResult;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Generate XML representation of this node's configuration.
  *
  * @param DOMElement $element
  * @ignore
  */
 public function configurationToXML(DOMElement $element)
 {
     $element->setAttribute('serviceObjectClass', $this->configuration['class']);
     if (!empty($this->configuration['arguments'])) {
         $xmlArguments = $element->appendChild($element->ownerDocument->createElement('arguments'));
         foreach ($this->configuration['arguments'] as $argument) {
             $xmlArguments->appendChild(ezcWorkflowDefinitionStorageXml::variableToXml($argument, $element->ownerDocument));
         }
     }
 }
All Usage Examples Of ezcWorkflowDefinitionStorageXml::variableToXml