I'm looking for a solution to use throughout the SDK to return all keys and values from the response object. There must be a way to traverse the response object in Ebay SDK PHP (davidtsadler/ebay-sdk-php).
Since each node is an object, I guess this is a 'multidimensional object'?? Even within those, there are arrays. See a small structure below:
I want to print the node/key names to build a "select node/section" tool, then use a loop for the values from the nodes selected. This way I can select any available field in a full response to build my custom reports.
I can handle the UI, but I can't seem to get the object to return keys/values without typing every key name individually.
foreach and implode only got me so far, then I still had to write the names.
(This sample below is only a SMALL fraction of this response nodes; here is the full model: http://developer.ebay.com/DevZone/XML/docs/Reference/eBay/GetMyeBaySelling.html)
<!-- Call-specific Input Fields -->
<ActiveList> ItemListCustomizationType
<Include> boolean </Include>
<IncludeNotes> boolean </IncludeNotes>
<ListingType> ListingTypeCodeType </ListingType>
<Pagination> PaginationType
<EntriesPerPage> int </EntriesPerPage>
<PageNumber> int </PageNumber>
</Pagination>
<Sort> ItemSortTypeCodeType </Sort>
</ActiveList>
<BidList> ItemListCustomizationType
<Include> boolean </Include>
<IncludeNotes> boolean </IncludeNotes>
<Pagination> PaginationType
<EntriesPerPage> int </EntriesPerPage>
<PageNumber> int </PageNumber>
</Pagination>
<Sort> ItemSortTypeCodeType </Sort>
</BidList>
<DeletedFromSoldList> ItemListCustomizationType
<DurationInDays> int </DurationInDays>
<Include> boolean </Include>
<IncludeNotes> boolean </IncludeNotes>
<Sort> ItemSortTypeCodeType </Sort>
</DeletedFromSoldList>
<DeletedFromUnsoldList> ItemListCustomizationType
<DurationInDays> int </DurationInDays>
<Include> boolean </Include>
<IncludeNotes> boolean </IncludeNotes>
<Sort> ItemSortTypeCodeType </Sort>
</DeletedFromUnsoldList> ....
There is a toArray method that can be called on any of the SDK's objects. The object's property names will become the keys in the associative array that is returned. The value for each key is the value for the object's property. This value can be another associative array if the property's value is another object, or it can be a regular array if the value is an array of values. Using something like array_keys may mean it's possible to iterate the properties of an object. Beware that toArray will only return an array that contains properties that have values. It won't return any properties that are empty.
Other than toArray there is no real way to iterate through the properties of an object as they are implemented using PHP's magic __get and __set methods. There may be ways that use PHP's refelection abilities but this will mean that you code is dependant upon private details of the SDK that can be changed or removed without notice.