From 5308e1d4184c720164cc1a7c1db14d23a0f69892 Mon Sep 17 00:00:00 2001 From: russpoutine Date: Fri, 13 Apr 2012 17:09:26 -0700 Subject: [PATCH] Enabled single objects without an array in request body It's no longer (since d11524cb4) possible to POST/PUT a single object without wrapping it in an array - API requires any object in the request body, even if there is just one, to be within an array. Since some projects do use single object calls without an array, this commit re-enables automatic array wrapping of single objects. --- lib/Api/ApiRequest.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Api/ApiRequest.php b/lib/Api/ApiRequest.php index dcbebfc..fe5cdc1 100755 --- a/lib/Api/ApiRequest.php +++ b/lib/Api/ApiRequest.php @@ -148,9 +148,12 @@ public function getMessageBody(){ } - //this allows a single object to be passed. this allows people that use the api - //to not have to wrap a single object in an array - if( isset($base_object_modifications[0]) && !is_array($base_object_modifications[0]) ){ + // This allows a single object to be passed. Peope who use the API + // to post/put a single object don't have to wrap it in an array + $base_object_keys = array_keys( $base_object_modifications ); + // if the first index is not numerical, + if ( ! empty($base_object_keys) && $base_object_keys[0] !== 0 ) { + // wrap modifications in another array $base_object_modifications = array( $base_object_modifications ); }