|
8 | 8 | final class QueryStringBuilder
|
9 | 9 | {
|
10 | 10 | /**
|
11 |
| - * Encode a query as a query string according to RFC 3986. Indexed arrays are encoded using |
12 |
| - * empty squared brackets ([]) unlike http_build_query. |
| 11 | + * Encode a query as a query string according to RFC 3986. |
| 12 | + * |
| 13 | + * Indexed arrays are encoded using empty squared brackets ([]) unlike |
| 14 | + * `http_build_query`. |
13 | 15 | *
|
14 | 16 | * @param mixed $query
|
15 | 17 | *
|
@@ -43,23 +45,23 @@ private static function encode($query, $prefix)
|
43 | 45 | return self::rawurlencode($prefix).'='.self::rawurlencode($query);
|
44 | 46 | }
|
45 | 47 |
|
46 |
| - $isIndexedArray = self::isIndexedArray($query); |
| 48 | + $isList = self::isList($query); |
47 | 49 |
|
48 |
| - return implode('&', array_map(function ($value, $key) use ($prefix, $isIndexedArray) { |
49 |
| - $prefix = $isIndexedArray ? $prefix.'[]' : $prefix.'['.$key.']'; |
| 50 | + return implode('&', array_map(function ($value, $key) use ($prefix, $isList) { |
| 51 | + $prefix = $isList ? $prefix.'[]' : $prefix.'['.$key.']'; |
50 | 52 |
|
51 | 53 | return self::encode($value, $prefix);
|
52 | 54 | }, $query, array_keys($query)));
|
53 | 55 | }
|
54 | 56 |
|
55 | 57 | /**
|
56 |
| - * Tell if the given array is an indexed one (i.e. contains only sequential integer keys starting from 0). |
| 58 | + * Tell if the given array is a list. |
57 | 59 | *
|
58 | 60 | * @param array $query
|
59 | 61 | *
|
60 | 62 | * @return bool
|
61 | 63 | */
|
62 |
| - public static function isIndexedArray(array $query) |
| 64 | + private static function isList(array $query) |
63 | 65 | {
|
64 | 66 | if (0 === count($query) || !isset($query[0])) {
|
65 | 67 | return false;
|
|
0 commit comments