|
@@ -3,6 +3,7 @@
|
|
|
namespace Mpociot\ApiDoc\Tools;
|
|
|
|
|
|
use Illuminate\Routing\Route;
|
|
|
+use Illuminate\Support\Arr;
|
|
|
use League\Flysystem\Adapter\Local;
|
|
|
use League\Flysystem\Filesystem;
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
|
@@ -116,18 +117,23 @@ class Utils
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
- public static function printQueryParamsAsString(array $cleanQueryParams)
|
|
|
+ public static function printQueryParamsAsString(array $cleanQueryParams): string
|
|
|
{
|
|
|
$qs = "";
|
|
|
foreach ($cleanQueryParams as $parameter => $value) {
|
|
|
$paramName = urlencode($parameter);
|
|
|
|
|
|
if (!is_array($value)) {
|
|
|
- $qs .= "$paramName=" . urlencode($value)."&";
|
|
|
+ $qs .= "$paramName=" . urlencode($value) . "&";
|
|
|
} else {
|
|
|
- // Query param is array - only one level of nesting supported
|
|
|
- foreach ($value as $item => $itemValue) {
|
|
|
- $qs .= "$paramName" . "[" . urlencode($item) . "]=" . urlencode($itemValue)."&";
|
|
|
+ if (array_keys($value)[0] === 0) {
|
|
|
+ // List query param (eg filter[]=haha should become "filter[]": "haha")
|
|
|
+ $qs .= "$paramName" . "[]=" . urlencode($value[0]) . "&";
|
|
|
+ } else {
|
|
|
+ // Hash query param (eg filter[name]=john should become "filter[name]": "john")
|
|
|
+ foreach ($value as $item => $itemValue) {
|
|
|
+ $qs .= "$paramName" . "[" . urlencode($item) . "]=" . urlencode($itemValue) . "&";
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -135,4 +141,37 @@ class Utils
|
|
|
|
|
|
return rtrim($qs, '&');
|
|
|
}
|
|
|
+
|
|
|
+ public static function printQueryParamsAsKeyValue(
|
|
|
+ array $cleanQueryParams,
|
|
|
+ string $quote = "\"",
|
|
|
+ string $delimiter = ":",
|
|
|
+ int $spacesIndentation = 4,
|
|
|
+ string $braces = "{}",
|
|
|
+ int $closingBraceIndentation = 0
|
|
|
+ ): string
|
|
|
+ {
|
|
|
+ $output = "{$braces[0]}\n";
|
|
|
+ foreach ($cleanQueryParams as $parameter => $value) {
|
|
|
+ if (!is_array($value)) {
|
|
|
+ $output .= str_repeat(" ", $spacesIndentation);
|
|
|
+ $output .= "$quote$parameter$quote$delimiter $quote$value$quote,\n";
|
|
|
+ } else {
|
|
|
+ if (array_keys($value)[0] === 0) {
|
|
|
+ // List query param (eg filter[]=haha should become "filter[]": "haha")
|
|
|
+ $output .= str_repeat(" ", $spacesIndentation);
|
|
|
+ $output .= "$quote$parameter"."[]$quote$delimiter $quote$value[0]$quote,\n";
|
|
|
+ } else {
|
|
|
+ // Hash query param (eg filter[name]=john should become "filter[name]": "john")
|
|
|
+ foreach ($value as $item => $itemValue) {
|
|
|
+ $output .= str_repeat(" ", $spacesIndentation);
|
|
|
+ $output .= "$quote$parameter"."[$item]$quote$delimiter $quote$itemValue$quote,\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $output.str_repeat(" ", $closingBraceIndentation)."{$braces[1]}";
|
|
|
+ }
|
|
|
}
|