@@ -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