private static function Braintree_Xml_Parser::_typecastXmlValue in Commerce Braintree 7
typecast xml value based on attributes
Parameters
object $valueObj SimpleXMLElement:
Return value
mixed value for placing into array
1 call to Braintree_Xml_Parser::_typecastXmlValue()
- Braintree_Xml_Parser::_iteratorToArray in braintree_php/
lib/ Braintree/ Xml/ Parser.php - processes SimpleXMLIterator objects recursively
File
- braintree_php/
lib/ Braintree/ Xml/ Parser.php, line 127
Class
- Braintree_Xml_Parser
- Parses incoming Xml into arrays using PHP's built-in SimpleXML, and its extension via Iterator, SimpleXMLIterator
Code
private static function _typecastXmlValue($valueObj) {
// get the element attributes
$attribs = $valueObj
->attributes();
// the element is null, so jump out here
if (isset($attribs->nil) && $attribs->nil) {
return null;
}
// switch on the type attribute
// switch works even if $attribs->type isn't set
switch ($attribs->type) {
case 'datetime':
return self::_timestampToUTC((string) $valueObj);
break;
case 'date':
return new DateTime((string) $valueObj);
break;
case 'integer':
return (int) $valueObj;
break;
case 'boolean':
$value = (string) $valueObj;
// look for a number inside the string
if (is_numeric($value)) {
return (bool) $value;
}
else {
// look for the string "true", return false in all other cases
return $value != "true" ? FALSE : TRUE;
}
break;
case 'array':
return array();
default:
return (string) $valueObj;
}
}