Skip to content

Commit 43907c1

Browse files
fix(Arguments): Fixed url generation when using array with enums as values
1 parent 2092164 commit 43907c1

4 files changed

Lines changed: 54 additions & 2 deletions

File tree

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
"psr-4": {
3333
"ZEROSPAM\\Framework\\SDK\\": "src/",
3434
"ZEROSPAM\\Framework\\SDK\\Test\\Base\\": "tests/src/Base"
35-
}
35+
},
36+
"files": [
37+
"src/Utils/Helpers/array.php"
38+
]
3639
},
3740
"autoload-dev": {
3841
"psr-4": {

src/Request/Arguments/Stackable/SubKeyedArrayStackableRequestArg.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
use ZEROSPAM\Framework\SDK\Request\Arguments\RequestArg;
13+
use ZEROSPAM\Framework\SDK\Utils\Contracts\PrimalValued;
1314

1415
/**
1516
* Class SubKeyedArrayStackableRequestArg
@@ -44,6 +45,10 @@ public function getSubKey(): string
4445
*/
4546
public function toPrimitive()
4647
{
47-
return $this->value;
48+
return array_map_r(function ($data) {
49+
return $data instanceof PrimalValued
50+
? $data->toPrimitive()
51+
: $data;
52+
}, $this->value);
4853
}
4954
}

src/Utils/Helpers/array.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: pbb
5+
* Date: 25/09/18
6+
* Time: 2:51 PM
7+
*/
8+
9+
if (!function_exists('array_map_r')) {
10+
11+
/**
12+
* @param $callback
13+
* @param $input
14+
*
15+
* @return array
16+
*/
17+
function array_map_r($callback, $input)
18+
{
19+
$output = [];
20+
foreach ($input as $key => $data) {
21+
if (is_array($data)) {
22+
$output[$key] = array_map_r($callback, $data);
23+
} else {
24+
$output[$key] = $callback($data);
25+
}
26+
}
27+
return $output;
28+
}
29+
}

tests/src/Tests/Argument/StackableArgumentTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use ZEROSPAM\Framework\SDK\Test\Base\Argument\SearchArgumentArray;
1313
use ZEROSPAM\Framework\SDK\Test\Base\Data\TestRequest;
1414
use ZEROSPAM\Framework\SDK\Test\Base\TestCase;
15+
use ZEROSPAM\Framework\SDK\Test\Tests\Utils\Obj\BasicEnum;
1516

1617
class StackableArgumentTest extends TestCase
1718
{
@@ -105,6 +106,20 @@ public function testArrayStackableInUrl(): void
105106
$this->validateQuery($client, 'search[statusids][]=1', 'search[statusids][]=2');
106107
}
107108

109+
/**
110+
*
111+
*/
112+
public function testArrayStackableWithEnums(): void
113+
{
114+
$client = $this->preSuccess([]);
115+
116+
$request = new TestRequest();
117+
$request->addArgument(new SearchArgumentArray('statusids', [BasicEnum::OTHER(), BasicEnum::TEST()]));
118+
$client->getOAuthTestClient()
119+
->processRequest($request);
120+
$this->validateQuery($client, 'search[statusids][]=other', 'search[statusids][]=test');
121+
}
122+
108123
/**
109124
*
110125
*/

0 commit comments

Comments
 (0)