Skip to content

Commit 1d0ea6b

Browse files
committed
fixed: should not display 'isAlone' command. some update for Phar compiler
1 parent f1d35ce commit 1d0ea6b

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

examples/app

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/usr/bin/env php
22
<?php
3+
/**
4+
* @version {@package_version}
5+
* @branch {@package_branch_alias_version}
6+
* @release-date {@release_date}
7+
*/
38

49
define('BASE_PATH', dirname(__DIR__));
510

src/Base/AbstractCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ protected function showHelp(): bool
208208
$help['usage'] = sprintf('%s %s %s', $this->input->getScript(), $this->input->getCommand(), $help['usage']);
209209
$help['global options:'] = FormatUtil::alignmentOptions(Application::getInternalOptions());
210210

211-
if (empty($help['description']) && $this->isAloneCommand()) {
211+
if (empty($help['description']) && $this->isAlone()) {
212212
$help['description'] = self::getDefinition();
213213
}
214214

@@ -390,7 +390,7 @@ protected function parseAnnotationVars(string $str): string
390390
/**
391391
* @return bool
392392
*/
393-
public function isAloneCommand(): bool
393+
public function isAlone(): bool
394394
{
395395
return $this instanceof CommandInterface;
396396
}

src/Components/PharCompiler.php

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ class PharCompiler
5555
* 记录上面三个信息的文件, 相对于basePath
5656
* 当里面存在下面的占位符时会自动替换为获取到的信息
5757
* [
58-
* 'version' => '@package_version@',
59-
* 'tag' => '@package_branch_alias_version@',
60-
* 'releaseDate' => '@release_date@',
58+
* 'version' => '{@package_version}',
59+
* 'tag' => '{@package_branch_alias_version}',
60+
* 'releaseDate' => '{@release_date}',
6161
* ]
6262
* @var string
6363
*/
@@ -88,6 +88,11 @@ class PharCompiler
8888
*/
8989
private $files = [];
9090

91+
/**
92+
* @var array Want to include files suffix name list
93+
*/
94+
private $suffixes = ['.php'];
95+
9196
/**
9297
* @var array Want to exclude directory name list
9398
*/
@@ -185,6 +190,17 @@ public function __construct(string $basePath)
185190
}
186191
}
187192

193+
/**
194+
* @param string|array $suffixes
195+
* @return $this
196+
*/
197+
public function addSuffix($suffixes): self
198+
{
199+
$this->suffixes = array_merge($this->suffixes, (array)$suffixes);
200+
201+
return $this;
202+
}
203+
188204
/**
189205
* @param string|array $dirs
190206
* @return $this
@@ -280,6 +296,7 @@ public function pack(string $pharFile, $refresh = true): string
280296

281297
$this->pharFile = $pharFile;
282298
$this->pharName = $pharName = basename($this->pharFile);
299+
$this->excludes = array_flip($this->excludes);
283300

284301
$this->collectInformation();
285302

@@ -380,9 +397,9 @@ private function packFile(\Phar $phar, \SplFileInfo $file)
380397
// have versionFile
381398
if ($path === $this->versionFile) {
382399
$content = str_replace([
383-
'@package_version@',
384-
'@package_branch_alias_version@',
385-
'@release_date@',
400+
'{@package_version}',
401+
'{@package_branch_alias_version}',
402+
'{@release_date}',
386403
], [
387404
$this->version,
388405
$this->branchAliasVersion,
@@ -494,17 +511,22 @@ private function createIteratorFilter(): \Closure
494511
return false;
495512
}
496513

514+
// skip exclude directories.
497515
if ($file->isDir()) {
498-
// Only recurse into intended subdirectories.
499-
return !\in_array($name, $this->excludes, true);
516+
return !isset($this->excludes[$name]);
500517
}
501518

502-
// if (\in_array($name, $this->options['fileInclude'], true)) {
503-
// return true;
504-
// }
519+
if ($this->suffixes) {
520+
foreach ($this->suffixes as $suffix) {
521+
if (stripos($name, $suffix)) {
522+
return true;
523+
}
524+
}
525+
526+
return false;
527+
}
505528

506-
// Only consume files of interest.
507-
return (bool)stripos($name, '.php');
529+
return true;
508530
};
509531
}
510532

@@ -581,7 +603,7 @@ private function collectInformation()
581603
$this->version = trim($ret);
582604
} else {
583605
list($code, $ret,) = CliUtil::run('git branch', $basePath);
584-
$this->branchAliasVersion = $code === 0 ? trim($ret): 'UNKNOWN';
606+
$this->branchAliasVersion = $code === 0 ? trim($ret, '* '): 'UNKNOWN';
585607
}
586608
}
587609

0 commit comments

Comments
 (0)