diff --git a/app/Console/Controller/JsonController.php b/app/Console/Controller/JsonController.php index 058fc54..e54382e 100644 --- a/app/Console/Controller/JsonController.php +++ b/app/Console/Controller/JsonController.php @@ -211,7 +211,7 @@ public function getCommand(FlagsParser $fs, Output $output): void } // is json string - if (is_string($ret) && str_starts_with($ret, '{"')) { + if (is_string($ret) && (str_starts_with($ret, '{"') || str_starts_with($ret, '[{"'))) { $output->info("find '$path' value is JSON string, auto decode"); $ret = Json::decode($ret, true); } diff --git a/app/Lib/Parser/Text/TextParser.php b/app/Lib/Parser/Text/TextParser.php index 2b81f07..3449d9d 100644 --- a/app/Lib/Parser/Text/TextParser.php +++ b/app/Lib/Parser/Text/TextParser.php @@ -136,20 +136,29 @@ class TextParser /** * @param string $text + * @param callable|null $setFn = function($p TextParser) {} * * @return self */ - public static function new(string $text = ''): self + public static function new(string $text = '', callable $setFn = null): self { - return new self($text); + $self = new self($text); + + if ($setFn) { + $setFn($self); + } + return $self; } /** + * @param string $text + * @param callable|null $setFn = function($p TextParser) {} + * * @return static */ - public static function parseText(string $text): self + public static function parseText(string $text, callable $setFn = null): self { - return (new self($text))->parse(); + return (new self($text, $setFn))->parse(); } /** @@ -163,6 +172,7 @@ public static function emptyWithParser(callable $itemParser): self } /** + * @param string $text * @param callable(string):array $itemParser * * @return static diff --git a/task/http-serve.md b/task/http-serve.md new file mode 100644 index 0000000..84b0af6 --- /dev/null +++ b/task/http-serve.md @@ -0,0 +1,7 @@ +# http serve + +## Run + +```shell +go run main.go +```