Skip to content

Commit a47bc1d

Browse files
committed
update some for phar controller
1 parent 0b65ccc commit a47bc1d

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

src/AbstractHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ protected function createDefinition(): InputDefinition
208208
protected function annotationVars(): array
209209
{
210210
$fullCmd = $this->input->getFullCommand();
211+
$binFile = $this->input->getScript(); // bin/app
211212
$binName = $this->input->getScriptName();
212213
$command = $this->input->getCommand();
213214

@@ -216,7 +217,8 @@ protected function annotationVars(): array
216217
'name' => self::getName(),
217218
'group' => self::getName(),
218219
'workDir' => $this->input->getPwd(),
219-
'script' => $this->input->getScript(), // bin/app
220+
'script' => $binFile, // bin/app
221+
'binFile' => $binFile, // bin/app
220222
'binName' => $binName, // app
221223
'scriptName' => $binName, // app
222224
'command' => $command, // demo OR home:test

src/BuiltIn/PharController.php

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,26 @@ class PharController extends Controller
4141
*/
4242
private $compilerConfiger;
4343

44-
protected function init(): void
44+
/**
45+
* @var string
46+
*/
47+
private $defPkgName;
48+
49+
protected static function commandAliases(): array
50+
{
51+
return [
52+
'pack' => ['build']
53+
];
54+
}
55+
56+
/**
57+
* @param Input $input
58+
*/
59+
protected function packConfigure(Input $input): void
4560
{
46-
parent::init();
61+
$this->defPkgName = trim(basename($input->getPwd()), '.') . PharCompiler::FILE_EXT;
4762

48-
$this->addCommentsVar('defaultPkgName', basename($this->input->getPwd()));
63+
$this->addCommentsVar('defaultPkgName', $this->defPkgName);
4964
}
5065

5166
/**
@@ -54,9 +69,9 @@ protected function init(): void
5469
*
5570
* @options
5671
* -d, --dir STRING Setting the project directory for packing.
57-
* default is current work-dir.(<cyan>{workDir}</cyan>)
58-
* -c, --config STRING Use the custom config file for build phar(<cyan>./phar.build.inc</cyan>)
59-
* -o, --output STRING Setting the output file name(<cyan>{defaultPkgName}.phar</cyan>)
72+
* default is current work-dir(default: <cyan>{workDir}</cyan>)
73+
* -c, --config STRING Use the custom config file for build phar(default: <cyan>./phar.build.inc</cyan>)
74+
* -o, --output STRING Setting the output file name(<cyan>{defaultPkgName}</cyan>)
6075
* --fast Fast build. only add modified files by <cyan>git status -s</cyan>
6176
* --refresh Whether build vendor folder files on phar file exists(<cyan>False</cyan>)
6277
* --files STRING Only pack the list files to the exist phar, multi use ',' split
@@ -68,25 +83,25 @@ protected function init(): void
6883
* @return int
6984
* @throws Exception
7085
* @example
71-
* {fullCommand} Pack current dir to a phar file.
72-
* {fullCommand} --dir vendor/swoft/devtool Pack the specified dir to a phar file.
86+
* {fullCommand} Pack current dir to a phar file.
87+
* {fullCommand} --dir vendor/swoft/devtool Pack the specified dir to a phar file.
7388
*
74-
* custom output phar file name
89+
* custom output phar file name
7590
* php -d phar.readonly=0 {binFile} phar:pack -o=mycli.phar
7691
*
77-
* only update the input files:
92+
* only update the input files:
7893
* php -d phar.readonly=0 {binFile} phar:pack -o=mycli.phar --debug --files app/Command/ServeCommand.php
7994
*/
8095
public function packCommand($input, $output): int
8196
{
82-
$startAt = microtime(1);
97+
$startAt = microtime(true);
8398
$workDir = $input->getPwd();
8499

85100
$dir = $input->getOpt('dir') ?: $workDir;
86101
$cpr = $this->configCompiler($dir);
87102

88103
$refresh = $input->boolOpt('refresh');
89-
$outFile = $input->sameOpt(['o', 'output'], basename($workDir) . '.phar');
104+
$outFile = $input->getSameStringOpt(['o', 'output'], $this->defPkgName);
90105
$pharFile = $workDir . '/' . $outFile;
91106

92107
Show::aList([
@@ -186,7 +201,7 @@ private function outputProgress(PharCompiler $cpr,Input $input): void
186201
});
187202
} else {
188203
$counter = Show::counterTxt('Collecting ...', 'Done.');
189-
$cpr->onAdd(function () use ($counter) {
204+
$cpr->onAdd(static function () use ($counter) {
190205
$counter->send(1);
191206
});
192207
$cpr->on(PharCompiler::ON_COLLECTED, function () use ($counter) {

src/Component/PharCompiler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class PharCompiler
6666

6767
public const ON_COLLECTED = 'collected';
6868

69+
public const FILE_EXT = '.phar';
70+
6971
/** @var array */
7072
private static $supportedSignatureTypes = [
7173
Phar::SHA512 => 1,

src/Traits/UserInteractAwareTrait.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
* @method array checkbox(string $description, $options, $default = null, $allowExit = true)
2626
* @method array multiSelect(string $description, $options, $default = null, $allowExit = true)
2727
*
28-
* @method unConfirm(string $question, bool $default = true): bool
29-
*
3028
* @method string askHiddenInput(string $prompt = 'Enter Password:')
3129
* @method string promptSilent(string $prompt = 'Enter Password:')
3230
* @method string askPassword(string $prompt = 'Enter Password:')
@@ -71,6 +69,17 @@ public function confirm(string $question, bool $default = true): bool
7169
return Interact::confirm($question, $default);
7270
}
7371

72+
/**
73+
* @param string $question
74+
* @param bool $default
75+
*
76+
* @return bool
77+
*/
78+
public function unConfirm(string $question, bool $default = true): bool
79+
{
80+
return Interact::unConfirm($question, $default);
81+
}
82+
7483
/**
7584
* @param string $question
7685
* @param string $default

0 commit comments

Comments
 (0)