Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.9.0

Bug #6430 No unified return values
Submitted: 2006-01-06 14:34 UTC
From: schst Assigned: ttsuruoka
Status: Closed Package: Services_Amazon
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2006-01-06 14:34 UTC] schst
Description: ------------ In a lot of cases, the user scripts have to check, whether a value is a string or an array, depending on whether the element exist one or more times in the returned document. This can be solved by XML_Unserializer, here's a patch, that also uses constants for the XML_Unserializer options (needs 0.17.0 or higher): Index: Services_Amazon/AmazonECS4.php =================================================================== RCS file: /repository/pear/Services_Amazon/AmazonECS4.php,v retrieving revision 1.1 diff -u -r1.1 AmazonECS4.php --- Services_Amazon/AmazonECS4.php 25 Nov 2005 01:43:49 -0000 1.1 +++ Services_Amazon/AmazonECS4.php 6 Jan 2006 14:26:30 -0000 @@ -934,7 +934,9 @@ } $result = $http->getResponseBody(); - $xml = &new XML_Unserializer(array('parseAttributes' => true)); + $xml = &new XML_Unserializer(); + $xml->setOption(XML_UNSERIALIZER_OPTION_ATTRIBUTES_PARSE, true); + $xml->setOption(XML_UNSERIALIZER_OPTION_FORCE_ENUM, array('Item', 'Parameter', 'ResponseGroup')); $xml->unserialize($result, false); $data = $xml->getUnserializedData(); Index: Services_Amazon/package.xml =================================================================== RCS file: /repository/pear/Services_Amazon/package.xml,v retrieving revision 1.2 diff -u -r1.2 package.xml --- Services_Amazon/package.xml 25 Nov 2005 02:13:15 -0000 1.2 +++ Services_Amazon/package.xml 6 Jan 2006 14:23:27 -0000 @@ -42,7 +42,7 @@ <deps> <dep type="pkg" rel="has" optional="no">PEAR</dep> <dep type="pkg" rel="has" optional="no">HTTP_Request</dep> - <dep type="pkg" rel="has" optional="no">XML_Serializer</dep> + <dep type="pkg" rel="ge" optional="no" version="0.17.0">XML_Serializer</dep> <dep type="pkg" rel="has" optional="yes">Cache</dep> </deps> <filelist> Test script: --------------- $amazon = new Services_AmazonECS4(....); $options = array(); $options['Title'] = 'PEAR DB'; $result = $amazon->ItemSearch('Books', $options); foreach ($result['Item'] as $book) { $title = $book['ItemAttributes']['Title']; $author = $book['ItemAttributes']['Author']; if (is_array($author)) { $author = implode(', ', $author); } printf("%s by %s\n", $title, $author); } The script will fail, but if you search only for "PEAR" it will work. Expected result: ---------------- Display the results. Actual result: -------------- PHP error message.

Comments

 [2006-01-07 15:32 UTC] ttsuruoka at php dot net
This has been fixed in CVS. Thank you for your detailed explanation and good solution!