Skip to content

Commit 07a1e51

Browse files
committed
refacting: update all use cli color tag class
1 parent ae9e9f6 commit 07a1e51

File tree

13 files changed

+46
-18
lines changed

13 files changed

+46
-18
lines changed

src/Component/Formatter/JSONPretty.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,40 @@ class JSONPretty extends AbstractObj
6565
* @param string $json
6666
*
6767
* @return string
68-
* @throws JsonException
68+
*/
69+
public static function prettyJSON(string $json): string
70+
{
71+
return (new self)->render($json);
72+
}
73+
74+
/**
75+
* @param mixed $data
76+
*
77+
* @return string
78+
*/
79+
public static function pretty(mixed $data): string
80+
{
81+
return (new self)->renderData($data);
82+
}
83+
84+
/**
85+
* @param mixed $data
86+
*
87+
* @return string
88+
*/
89+
public static function prettyData(mixed $data): string
90+
{
91+
return (new self)->renderData($data);
92+
}
93+
94+
/**
95+
* @param string $json
96+
*
97+
* @return string
6998
*/
7099
public function render(string $json): string
71100
{
72-
$data = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
101+
$data = JsonHelper::decode($json, true);
73102

74103
return $this->renderData($data);
75104
}
@@ -79,7 +108,7 @@ public function render(string $json): string
79108
*
80109
* @return string
81110
*/
82-
public function renderData(array $data): string
111+
public function renderData(mixed $data): string
83112
{
84113
$buf = StrBuffer::new();
85114
$json = JsonHelper::prettyJSON($data);

src/Component/Formatter/Padding.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use Inhere\Console\Component\MessageFormatter;
1313
use Inhere\Console\Console;
14-
use Toolkit\Cli\ColorTag;
14+
use Toolkit\Cli\Color\ColorTag;
1515
use Toolkit\Stdlib\Arr\ArrayHelper;
1616
use Toolkit\Stdlib\Str;
1717
use function array_merge;

src/Component/Formatter/SingleList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Inhere\Console\Component\MessageFormatter;
1313
use Inhere\Console\Console;
1414
use Inhere\Console\Util\FormatUtil;
15-
use Toolkit\Cli\ColorTag;
15+
use Toolkit\Cli\Color\ColorTag;
1616
use Toolkit\Stdlib\Str;
1717
use function array_merge;
1818
use function trim;

src/Component/Formatter/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use Inhere\Console\Component\MessageFormatter;
1313
use Inhere\Console\Console;
14-
use Toolkit\Cli\ColorTag;
14+
use Toolkit\Cli\Color\ColorTag;
1515
use Toolkit\Stdlib\Str;
1616
use Toolkit\Stdlib\Str\StrBuffer;
1717
use function array_keys;

src/Component/Formatter/Title.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use Inhere\Console\Component\MessageFormatter;
1313
use Inhere\Console\Console;
14-
use Toolkit\Cli\ColorTag;
14+
use Toolkit\Cli\Color\ColorTag;
1515
use Toolkit\Stdlib\Str;
1616
use Toolkit\Sys\Sys;
1717
use function array_merge;

src/Component/Symbol/ArtFont.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Inhere\Console\Component\Symbol;
1111

1212
use Inhere\Console\Console;
13-
use Toolkit\Cli\ColorTag;
13+
use Toolkit\Cli\Color\ColorTag;
1414
use function dirname;
1515
use function file_get_contents;
1616
use function in_array;

src/Concern/ApplicationHelpTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Inhere\Console\IO\Output;
1818
use Inhere\Console\Util\FormatUtil;
1919
use Inhere\Console\Util\Show;
20-
use Toolkit\Cli\ColorTag;
20+
use Toolkit\Cli\Color\ColorTag;
2121
use Toolkit\Cli\Style;
2222
use function array_merge;
2323
use function basename;

src/Concern/ControllerHelpTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Inhere\Console\GlobalOption;
1414
use Inhere\Console\Util\FormatUtil;
1515
use ReflectionClass;
16-
use Toolkit\Cli\ColorTag;
16+
use Toolkit\Cli\Color\ColorTag;
1717
use Toolkit\Stdlib\Str;
1818
use Toolkit\Stdlib\Util\PhpDoc;
1919
use function array_merge;

src/Concern/FormatOutputAwareTrait.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
namespace Inhere\Console\Concern;
1111

12+
use Inhere\Console\Component\Formatter\JSONPretty;
1213
use Inhere\Console\Console;
13-
use Toolkit\Stdlib\Helper\JsonHelper;
14+
use Toolkit\Stdlib\Json;
1415
use Toolkit\Stdlib\Php;
1516
use function array_merge;
1617
use function count;
1718
use function implode;
18-
use function json_encode;
1919
use const PHP_EOL;
2020

2121
/**
@@ -133,7 +133,7 @@ public function json(
133133
bool $echo = true,
134134
int $flags = JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
135135
): int|string {
136-
$string = json_encode($data, $flags);
136+
$string = Json::encode($data, $flags);
137137

138138
if ($echo) {
139139
return Console::write($string);
@@ -152,7 +152,7 @@ public function prettyJSON(mixed $data, string $title = 'JSON:'): void
152152
Console::colored($title, 'ylw0');
153153
}
154154

155-
Console::write(JsonHelper::prettyJSON($data));
155+
Console::write(JSONPretty::pretty($data));
156156
}
157157

158158
/**

src/Console.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Inhere\Console\IO\Input;
1313
use Inhere\Console\IO\Output;
1414
use Toolkit\Cli\Cli;
15-
use Toolkit\Cli\ColorTag;
15+
use Toolkit\Cli\Color\ColorTag;
1616
use function date;
1717
use function debug_backtrace;
1818
use function implode;

0 commit comments

Comments
 (0)