Skip to content

Commit

Permalink
👔 up: update json commands and text parser logic
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Feb 8, 2023
1 parent ec8ceeb commit a655cca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/Console/Controller/JsonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 14 additions & 4 deletions app/Lib/Parser/Text/TextParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand All @@ -163,6 +172,7 @@ public static function emptyWithParser(callable $itemParser): self
}

/**
* @param string $text
* @param callable(string):array $itemParser
*
* @return static
Expand Down
7 changes: 7 additions & 0 deletions task/http-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# http serve

## Run

```shell
go run main.go
```

0 comments on commit a655cca

Please sign in to comment.