/**
* Map variable access onto the underlying entry representation.
*
* Get-style access returns a Horde_Xml_Element representing the
* child element accessed. To get string values, use method syntax
* with the __call() overriding.
*
* @param string $var The property to access.
* @return mixed
*/
public function __get($var)
{
$nodes = $this->_children($var);
$length = count($nodes);
if ($length == 1) {
if ($nodes[0] instanceof Horde_Xml_Element) {
return $nodes[0];
}
return new Horde_Xml_Element($nodes[0]);
} elseif ($length > 1) {
if ($nodes[0] instanceof Horde_Xml_Element) {
return $nodes;
}
return array_map(function ($e) {
return new Horde_Xml_Element($e);
}, $nodes);
} else {
// When creating anonymous nodes for __set chaining, don't
// call appendChild() on them. Instead we pass the current
// element to them as an extra reference; the child is
// then responsible for appending itself when it is
// actually set. This way "if ($foo->bar)" doesn't create
// a phantom "bar" element in our tree.
if (strpos($var, ':') !== false) {
list($ns, $elt) = explode(':', $var, 2);
$node = $this->_element->ownerDocument->createElementNS(Horde_Xml_Element::lookupNamespace($ns), $elt);
} else {
$node = $this->_element->ownerDocument->createElement($var);
}
$node = new Horde_Xml_Element($node);
$node->setParent($this);
return $node;
}
}