public function testSetName() { $vh = new AgaviConfigValueHolder(); $vh->setName('test1'); $this->assertSame('test1', $vh->getName()); $vh->setName('test2'); $this->assertSame('test2', $vh->getName()); }
/** * Iterates through a list of nodes and stores to each node in the * ConfigValueHolder * * @param mixed An array or an object that can be iterated over * @param AgaviXmlValueHolder The storage for the info from the nodes * @param bool Whether this list is the singular form of the parent node * * @author David Zülke <*****@*****.**> * @author Dominik del Bondio <*****@*****.**> * @since 0.11.0 */ protected function parseNodes($nodes, AgaviConfigValueHolder $parentVh, $isSingular = false) { foreach ($nodes as $node) { if ($node->nodeType == XML_ELEMENT_NODE && (!$node->namespaceURI || $node->namespaceURI == AgaviXmlConfigParser::NAMESPACE_AGAVI_ENVELOPE_0_11)) { $vh = new AgaviConfigValueHolder(); $nodeName = $this->convertEncoding($node->localName); $vh->setName($nodeName); $parentVh->addChildren($nodeName, $vh); foreach ($node->attributes as $attribute) { if (!$attribute->namespaceURI || $attribute->namespaceURI == AgaviXmlConfigParser::NAMESPACE_AGAVI_ENVELOPE_0_11) { $vh->setAttribute($this->convertEncoding($attribute->localName), $this->convertEncoding($attribute->nodeValue)); } } // there are no child nodes so we set the node text contents as the value for the valueholder if ($node->getElementsByTagName('*')->length == 0) { $vh->setValue($this->convertEncoding($node->nodeValue)); } if ($node->hasChildNodes()) { $this->parseNodes($node->childNodes, $vh); } } } }
/** * Magic getter overload. * * @param string Name of the child . * * @return AgaviConfigValueHolder The child, if it exists. * * @author Dominik del Bondio <*****@*****.**> * @since 0.11.0 */ public function __get($name) { if (isset($this->_childs[$name])) { return $this->_childs[$name]; } else { $tagName = $name; $tagNameStart = ''; if (($lastUScore = strrpos($tagName, '_')) !== false) { $lastUScore++; $tagNameStart = substr($tagName, 0, $lastUScore); $tagName = substr($tagName, $lastUScore); } // check if the requested node was specified using the plural version // and create a "virtual" node which reflects the non existent plural node $singularName = $tagNameStart . AgaviInflector::singularize($tagName); if ($this->hasChildren($singularName)) { $vh = new AgaviConfigValueHolder(); $vh->setName($name); foreach ($this->_childs as $child) { if ($child->getName() == $singularName) { $vh->addChildren($singularName, $child); } } return $vh; } else { //throw new AgaviException('Node with the name ' . $name . ' does not exist ('.$this->getName().', '.implode(', ', array_keys($this->_childs)).')'); return null; } } }