From 0a1a91f31eb7f71d174608f84280bfe105554f97 Mon Sep 17 00:00:00 2001 From: Christophe Willemsen Date: Tue, 7 Mar 2017 00:50:48 +0400 Subject: [PATCH 1/2] fix empty array in nested array not being translated to empty json collection --- src/HttpDriver/Session.php | 13 +++++-------- tests/Issues/Issue99Test.php | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 tests/Issues/Issue99Test.php diff --git a/src/HttpDriver/Session.php b/src/HttpDriver/Session.php index 9866376d..9e0bd7d0 100644 --- a/src/HttpDriver/Session.php +++ b/src/HttpDriver/Session.php @@ -193,6 +193,7 @@ public function prepareRequest(Pipeline $pipeline) $body = json_encode([ 'statements' => $statements, ]); + $headers = [ [ 'X-Stream' => true, @@ -205,15 +206,11 @@ public function prepareRequest(Pipeline $pipeline) private function formatParams(array $params) { - foreach ($params as $key => $v) { - if (is_array($v)) { - if (empty($v)) { - $params[$key] = new \stdClass(); - } else { - $params[$key] = $this->formatParams($params[$key]); - } + array_walk_recursive($params, function(&$v, $k) { + if (is_array($v) && count($v) === 0) { + $v = new \stdClass(); } - } + }); return $params; } diff --git a/tests/Issues/Issue99Test.php b/tests/Issues/Issue99Test.php new file mode 100644 index 00000000..2819e97c --- /dev/null +++ b/tests/Issues/Issue99Test.php @@ -0,0 +1,24 @@ + ['id' => 123, 'some' => []]]; + + $result = $this->client->run($q, $params); + + $this->assertEquals(1, $result->size()); + } +} \ No newline at end of file From b00ad4610eae8a92129374cc7026f3a752fcbaa9 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 7 Mar 2017 09:00:54 +0100 Subject: [PATCH 2/2] Remove contents in formatParams --- src/HttpDriver/Session.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/HttpDriver/Session.php b/src/HttpDriver/Session.php index 9e0bd7d0..2181f441 100644 --- a/src/HttpDriver/Session.php +++ b/src/HttpDriver/Session.php @@ -193,7 +193,7 @@ public function prepareRequest(Pipeline $pipeline) $body = json_encode([ 'statements' => $statements, ]); - + $headers = [ [ 'X-Stream' => true, @@ -206,12 +206,6 @@ public function prepareRequest(Pipeline $pipeline) private function formatParams(array $params) { - array_walk_recursive($params, function(&$v, $k) { - if (is_array($v) && count($v) === 0) { - $v = new \stdClass(); - } - }); - return $params; }