/** * <p> * Parses the value of property element. * </p> * * @param XmlElement $property * @param string $type the type of the value. * @return mixed */ public function getValue($element, $type = null) { // ** Retrieve the value of the property element, in this case, it's an attribute. $attr = $element->getAttribute('value'); if (!empty($attr)) { $attrs = $element->getAttributes(); return ConverterFactory::getInstance()->convert($attr, $type, $attrs); } // ** Attempts to retrieve the value, based on the first child (if there is one)... $firstChild = $element->getFirstChild(); if ($firstChild != null) { $name = $firstChild->getName(); if ($name == 'array') { return $this->parseArray($firstChild); } if ($name == 'object') { $object = $this->parseObject($firstChild, false); return $object !== null ? $object->getInstance() : null; } } // ** Finally attempts to retrieve the value based on the text node. $text = $element->getValue(); if (!empty($text)) { $attrs = $element->getAttributes(); return ConverterFactory::getInstance()->convert($text, $type, $attrs); } return null; }
public function testGetNullType() { $factory = ConverterFactory::getInstance(); $this->assertEquals('null', $factory->getType(null)); }