Skip to content

Commit 0b65ccc

Browse files
committed
update dep packages. update some class imports
1 parent 643580b commit 0b65ccc

18 files changed

+235
-151
lines changed

.php_cs

+20-10
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,31 @@ The file is part of inhere/console
99
EOF;
1010

1111
$rules = [
12-
'@PSR2' => true,
13-
'array_syntax' => [
12+
'@PSR2' => true,
13+
'array_syntax' => [
14+
'syntax' => 'short'
15+
],
16+
'list_syntax' => [
1417
'syntax' => 'short'
1518
],
1619
'class_attributes_separation' => true,
17-
'declare_strict_types' => true,
18-
'global_namespace_import' => true,
19-
'header_comment' => [
20+
'declare_strict_types' => true,
21+
'global_namespace_import' => [
22+
'import_constants' => true,
23+
'import_functions' => true,
24+
],
25+
'header_comment' => [
2026
'comment_type' => 'PHPDoc',
21-
'header' => $header,
22-
'separate' => 'bottom'
27+
'header' => $header,
28+
'separate' => 'bottom'
29+
],
30+
'no_unused_imports' => true,
31+
'return_type_declaration' => [
32+
'space_before' => 'none',
2333
],
24-
'no_unused_imports' => true,
25-
'single_quote' => true,
26-
'standardize_not_equals' => true,
34+
'single_quote' => true,
35+
'standardize_not_equals' => true,
36+
'void_return' => true, // add :void for method
2737
];
2838

2939
$finder = PhpCsFixer\Finder::create()

composer.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
"require": {
2525
"php": ">7.1.0",
2626
"toolkit/cli-utils": "~1.0",
27-
"toolkit/str-utils": "~1.0",
28-
"toolkit/php-utils": "~1.0",
27+
"toolkit/stdlib": "~1.0",
2928
"toolkit/sys-utils": "~1.0"
3029
},
3130
"require-dev": {

examples/Controller/HomeController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use RuntimeException;
1313
use Toolkit\Cli\Cli;
1414
use Toolkit\Cli\Download;
15-
use Toolkit\PhpUtil\Php;
15+
use Toolkit\Stdlib\Php;
1616
use function sleep;
1717
use function trigger_error;
1818

src/AbstractApplication.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use Inhere\Console\Traits\SimpleEventTrait;
2323
use InvalidArgumentException;
2424
use Throwable;
25-
use Toolkit\PhpUtil\PhpHelper;
25+
use Toolkit\Stdlib\Helper\PhpHelper;
2626
use function array_keys;
2727
use function array_merge;
2828
use function error_get_last;

src/AbstractHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use RuntimeException;
2525
use Swoole\Coroutine;
2626
use Swoole\Event;
27-
use Toolkit\PhpUtil\PhpDoc;
27+
use Toolkit\Stdlib\Util\PhpDoc;
2828
use function array_diff_key;
2929
use function array_filter;
3030
use function array_key_exists;

src/BuiltIn/PharController.php

+83-42
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
namespace Inhere\Console\BuiltIn;
1010

11-
use BadMethodCallException;
1211
use Closure;
1312
use Exception;
1413
use Inhere\Console\Component\PharCompiler;
@@ -18,7 +17,7 @@
1817
use Inhere\Console\Util\Helper;
1918
use Inhere\Console\Util\Show;
2019
use RuntimeException;
21-
use UnexpectedValueException;
20+
use Toolkit\Stdlib\Str;
2221
use function basename;
2322
use function file_exists;
2423
use function is_dir;
@@ -58,70 +57,78 @@ protected function init(): void
5857
* default is current work-dir.(<cyan>{workDir}</cyan>)
5958
* -c, --config STRING Use the custom config file for build phar(<cyan>./phar.build.inc</cyan>)
6059
* -o, --output STRING Setting the output file name(<cyan>{defaultPkgName}.phar</cyan>)
61-
* --fast BOOL Fast build. only add modified files by <cyan>git status -s</cyan>
62-
* --refresh BOOL Whether build vendor folder files on phar file exists(<cyan>False</cyan>)
60+
* --fast Fast build. only add modified files by <cyan>git status -s</cyan>
61+
* --refresh Whether build vendor folder files on phar file exists(<cyan>False</cyan>)
62+
* --files STRING Only pack the list files to the exist phar, multi use ',' split
63+
* --no-progress Disable output progress on the runtime
6364
*
64-
* @param Input $in
65-
* @param Output $out
65+
* @param Input $input
66+
* @param Output $output
6667
*
6768
* @return int
68-
* @throws UnexpectedValueException
69-
* @throws RuntimeException
70-
* @throws BadMethodCallException
7169
* @throws Exception
70+
* @example
71+
* {fullCommand} Pack current dir to a phar file.
72+
* {fullCommand} --dir vendor/swoft/devtool Pack the specified dir to a phar file.
73+
*
74+
* custom output phar file name
75+
* php -d phar.readonly=0 {binFile} phar:pack -o=mycli.phar
76+
*
77+
* only update the input files:
78+
* php -d phar.readonly=0 {binFile} phar:pack -o=mycli.phar --debug --files app/Command/ServeCommand.php
7279
*/
73-
public function packCommand($in, $out): int
80+
public function packCommand($input, $output): int
7481
{
75-
$time = microtime(1);
76-
$workDir = $in->getPwd();
82+
$startAt = microtime(1);
83+
$workDir = $input->getPwd();
7784

78-
$dir = $in->getOpt('dir') ?: $workDir;
85+
$dir = $input->getOpt('dir') ?: $workDir;
7986
$cpr = $this->configCompiler($dir);
8087

81-
$counter = null;
82-
$refresh = $in->boolOpt('refresh');
83-
$pharFile = $workDir . '/' . $in->sameOpt(['o', 'output'], basename($workDir) . '.phar');
88+
$refresh = $input->boolOpt('refresh');
89+
$outFile = $input->sameOpt(['o', 'output'], basename($workDir) . '.phar');
90+
$pharFile = $workDir . '/' . $outFile;
91+
92+
Show::aList([
93+
'work dir' => $workDir,
94+
'project' => $dir,
95+
'phar file' => $pharFile,
96+
], 'Building Information');
8497

8598
// use fast build
8699
if ($this->input->boolOpt('fast')) {
87100
$cpr->setModifies($cpr->findChangedByGit());
88101
$this->output->liteNote('Use fast build, will only pack changed or new files(from git status)');
89102
}
90103

91-
$out->liteInfo("Now, will begin building phar package.\n from path: <comment>$workDir</comment>\n" . " phar file: <info>$pharFile</info>");
104+
// Manual append some files
105+
if ($files = $input->getStringOpt('files')) {
106+
$cpr->setModifies(Str::explode($files));
107+
$output->liteInfo("will only pack input files to the exists phar: $outFile");
108+
}
92109

93-
$out->info('Pack file to Phar: ');
94110
$cpr->onError(function ($error) {
95-
$this->output->warning($error);
111+
$this->writeln("<warning>$error</warning>");
112+
});
113+
$cpr->on(PharCompiler::ON_MESSAGE, function ($msg) {
114+
$this->output->colored('> ' . $msg);
96115
});
97116

98-
if ($in->getOpt('debug')) {
99-
$cpr->onAdd(function ($path) {
100-
$this->output->write(" <comment>+</comment> $path");
101-
});
102-
} else {
103-
$counter = Show::counterTxt('Handling ...', 'Done.');
104-
$cpr->onAdd(function () use ($counter) {
105-
$counter->send(1);
106-
});
107-
}
117+
$output->colored('Collect Pack files', 'comment');
118+
$this->outputProgress($cpr, $input);
108119

109120
// packing ...
110121
$cpr->pack($pharFile, $refresh);
111122

112-
// end
113-
if ($counter) {
114-
$counter->send(-1);
115-
}
116-
117-
$out->write([
118-
PHP_EOL . '<success>Phar build completed!</success>',
119-
" - Phar file: $pharFile",
120-
' - Phar size: ' . round(filesize($pharFile) / 1024 / 1024, 2) . ' Mb',
121-
' - Pack Time: ' . round(microtime(1) - $time, 3) . ' s',
123+
$info = [
124+
PHP_EOL . '<success>Phar Build Completed!</success>',
122125
' - Pack File: ' . $cpr->getCounter(),
123-
' - Commit ID: ' . $cpr->getVersion(),
124-
]);
126+
' - Pack Time: ' . round(microtime(true) - $startAt, 3) . ' s',
127+
' - Phar Size: ' . round(filesize($pharFile) / 1024 / 1024, 2) . ' Mb',
128+
" - Phar File: $pharFile",
129+
' - Commit ID: ' . $cpr->getLastCommit(),
130+
];
131+
$output->writeln($info);
125132

126133
return 0;
127134
}
@@ -147,14 +154,48 @@ protected function configCompiler(string $dir): PharCompiler
147154
$configFile = $this->input->getSameOpt(['c', 'config']) ?: $dir . '/phar.build.inc';
148155

149156
if ($configFile && is_file($configFile)) {
157+
/** @noinspection PhpIncludeInspection */
150158
require $configFile;
151-
152159
return $compiler->in($dir);
153160
}
154161

155162
throw new RuntimeException("The phar build config file not exists! File: $configFile");
156163
}
157164

165+
/**
166+
* @param PharCompiler $cpr
167+
* @param Input $input
168+
*
169+
* @return void
170+
*/
171+
private function outputProgress(PharCompiler $cpr,Input $input): void
172+
{
173+
if ($input->getBoolOpt('no-progress')) {
174+
return;
175+
}
176+
177+
if ($input->getOpt('debug')) {
178+
// $output->info('Pack file to Phar ... ...');
179+
$cpr->onAdd(function (string $path) {
180+
$this->writeln(" <info>+</info> $path");
181+
});
182+
183+
$cpr->on('skip', function (string $path, bool $isFile) {
184+
$mark = $isFile ? '[F]' : '[D]';
185+
$this->writeln(" <red>-</red> $path <info>$mark</info>");
186+
});
187+
} else {
188+
$counter = Show::counterTxt('Collecting ...', 'Done.');
189+
$cpr->onAdd(function () use ($counter) {
190+
$counter->send(1);
191+
});
192+
$cpr->on(PharCompiler::ON_COLLECTED, function () use ($counter) {
193+
$counter->send(-1);
194+
$this->writeln('');
195+
});
196+
}
197+
}
198+
158199
/**
159200
* @param Closure $compilerConfiger
160201
*/

src/Component/Formatter/Panel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Inhere\Console\Component\MessageFormatter;
1212
use Inhere\Console\Console;
1313
use Inhere\Console\Util\FormatUtil;
14-
use Toolkit\StrUtil\StrBuffer;
14+
use Toolkit\Stdlib\Str\StrBuffer;
1515
use function array_filter;
1616
use function array_merge;
1717
use function ceil;

src/Component/Formatter/Section.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Inhere\Console\Component\MessageFormatter;
66
use Inhere\Console\Console;
77
use Inhere\Console\Util\FormatUtil;
8-
use Toolkit\StrUtil\Str;
8+
use Toolkit\Stdlib\Str;
99
use function array_merge;
1010
use function ceil;
1111
use function implode;

src/Component/Formatter/Table.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Inhere\Console\Component\MessageFormatter;
1212
use Inhere\Console\Console;
1313
use Toolkit\Cli\ColorTag;
14-
use Toolkit\StrUtil\StrBuffer;
14+
use Toolkit\Stdlib\Str\StrBuffer;
1515
use function array_keys;
1616
use function array_merge;
1717
use function array_sum;

src/Component/Formatter/Title.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Inhere\Console\Component\MessageFormatter;
66
use Inhere\Console\Console;
7-
use Toolkit\StrUtil\Str;
7+
use Toolkit\Stdlib\Str;
88
use Toolkit\Sys\Sys;
99
use function array_merge;
1010
use function ceil;

src/Component/MessageFormatter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Inhere\Console\Console;
1212
use Inhere\Console\Contract\FormatterInterface;
1313
use RuntimeException;
14-
use Toolkit\PhpUtil\PhpHelper;
14+
use Toolkit\Stdlib\Obj\ObjectHelper;
1515

1616
/**
1717
* Class Formatter - message formatter
@@ -49,7 +49,7 @@ public static function create(array $config = []): self
4949
*/
5050
public function __construct(array $config = [])
5151
{
52-
PhpHelper::initObject($this, $config);
52+
ObjectHelper::init($this, $config);
5353

5454
$this->config = $config;
5555
}

0 commit comments

Comments
 (0)