Posting this as a follow up to #945788: Change node.save argument type to array. There seems to have been a few issues with people not knowing if they should parse JSON into objects or arrays prior to passing the values as arguments to Services.
To simplify the servers I'm suggesting that the argument type 'struct' is removed in favor of the already existing argument type 'array'.
All values that can be represented as an object in an argument can also be represented as an array. Supporting two formats for the same thing just adds complexity. Sticking to arrays only makes a simpler interface.
Resources themselves can cast associative array into an objects if they want - that's much better.
What do you think - am I missing something crucial that justifies the existence of 'struct'?
| Comment | File | Size | Author |
|---|---|---|---|
| #22 | 954964-remove-struct-d6.patch | 16.99 KB | ygerasimov |
| #21 | 954964-remove-struct-followup.patch | 1.29 KB | ygerasimov |
| #18 | 954964-remove-struct-array-18.patch | 20.74 KB | marcingy |
| #17 | 954964-remove-struct-reviewed_1.patch | 19.81 KB | marcingy |
| #15 | 954964-remove-struct-reviewed.patch | 21.17 KB | ygerasimov |
Comments
Comment #1
gddIn the past I have always wanted the individual resources to match their underlying API calls (IE node_load() requires an object, so node.load should require one too.) However what has ended up happening is that in many of the services, we check to see if the argument is the correct format, and if not we cast it to whatever we want anyways. Having a constant rule that everything is an array would make it simpler on the end users and provide a more consistent interface, so +1 to this.
Now the question is, what needs to be done to support this? Is there any real change required other than modifying the Service definitions?
Comment #2
voxpelli commentedI think the Services browser would need to be changed as well - it's the only place I know that currently makes a difference between arrays and structs.
Might perhaps be good to harden some of the parsing in at least the REST Server as well - right now eg. the unserializing of PHP-serialized data can result in an object - it should be casted to an array then I think. The JSON and URL parsing is fine.
Does the XML-RPC Server need some hardening as well?
Comment #3
gddWell the browser is gone in 6.3, so that is not a problem anymore (well, not for us anyways.) I'm not sure what would have to be done in XMLRPC server. In theory nothing since all it really does is pass everything down to the core XMLRPC calls.
Comment #4
marcingy commentedThe xmlrpc server recieves all drupal objects as an array, so heyrocker's comment is correct nothing needs to be done it will continue to work.
Comment #5
marcingy commentedMoving to current version and setting as postponed for consideration in 7.4
Comment #6
voxpelli commentedSorry for reopening, but I think it is crucial to have this in 7.3 as we otherwise will have wrongly behaving servers (even the ones included in core - right?) So we either fix this little thing or we will have to fix the servers - I'd say we fix this.
(Reopened since I thought it made most sense to have it opened during the discussion - I've no intention to start a status war ;) )
Comment #7
marcingy commentedIf this needs to be 'fixed' in one or another then it makes sense to get it into 7.3, reclassifying as a task rather thana feature request.
Comment #8
ygerasimov commentedHere is patch that replaces 'struct' to 'array'.
Comment #9
kylebrowning commentedAll tests pass and looking over the code, im happy with everything here. Ill leave to needs review so others can post and if there are no objections Ill commit this before End of week.
Comment #10
marcingy commentedGoing through the code and I notice that in _user_resource_update we are still casting to an object is this by design?
It seems strange as we then cast back to an array here
So we process the incoming data as both an array and an object, as I say I might be missing something.
In _node_resource_create again we have something strange going on
As we cast to an object and then cast to an array, I am assuming the object cast can be replaced with the array cast. _node_resource_update has a similar issue. As does _comment_resource_create and _comment_resource_update.
Comment #11
marcingy commentedThis illustrates what I'm talking about to some extent http://drupalbin.com/18167 - maybe a little outside of scope but tidying this up would be nice.
Comment #12
marcingy commentedreroll including comment above
Comment #13
marcingy commentedNeed to remove the casts and tidy up patch
Comment #14
ygerasimov commentedI have rerolled patch. Fixed tests and trailing whitespaces based on #12.
Comment #15
ygerasimov commentedupload proper patch
Comment #16
kylebrowning commentedAfter quick glance it looks good to me.
Comment #17
marcingy commentedRemoves some unneeded casts
Comment #18
marcingy commentedLets try this instead
Comment #19
ygerasimov commentedI am happy with patch #18.
Comment #20
kylebrowning commentedComment #21
ygerasimov commentedOops. Please commit attached patch as well. As now parameters in node index method get NULL default value instead of empty array.
Comment #22
ygerasimov commentedHere is patch for 6.x-3.x.
Comment #23
kylebrowning commented