@@ -26,11 +26,12 @@ class PharController extends Controller
2626 * pack project to a phar package
2727 * @usage {fullCommand} [--dir DIR] [--output FILE]
2828 * @options
29- * --dir STRING Setting the directory for packing.
30- * - default is current work-dir.(<comment>{workDir}</comment>)
31- * --fast BOOL Fast build. only add modified files by <cyan>git status -s</cyan>
32- * --output STRING Setting the output file name(<comment>app.phar</comment>)
33- * --refresh BOOL Whether build vendor folder files on phar file exists(<comment>False</comment>)
29+ * --dir STRING Setting the project directory for packing.
30+ * - default is current work-dir.(<comment>{workDir}</comment>)
31+ * --fast BOOL Fast build. only add modified files by <cyan>git status -s</cyan>
32+ * -c, --config STRING Use the defined config for build phar.
33+ * --output STRING Setting the output file name(<comment>app.phar</comment>)
34+ * --refresh BOOL Whether build vendor folder files on phar file exists(<comment>False</comment>)
3435 * @param \Inhere\Console\IO\Input $in
3536 * @param \Inhere\Console\IO\Output $out
3637 * @return int
@@ -101,8 +102,21 @@ public function packCommand($in, $out): int
101102 protected function configCompiler (string $ dir ): PharCompiler
102103 {
103104 // config
104- $ cpr = new PharCompiler ($ dir );
105- $ cpr
105+ $ compiler = new PharCompiler ($ dir );
106+
107+ // if set config file.
108+ $ configFile = $ this ->input ->getSameOpt (['c ' , 'config ' ]) ?: $ dir . '/phar.build.inc ' ;
109+
110+ if ($ configFile && is_file ($ configFile )) {
111+ require $ configFile ;
112+
113+ $ compiler ->in ($ dir );
114+
115+ return $ compiler ;
116+ }
117+
118+ // you can also extend this controller, then config in the sub-class.
119+ $ compiler
106120 // ->stripComments(false)
107121 ->setShebang (true )
108122 ->addExclude ([
@@ -123,14 +137,14 @@ protected function configCompiler(string $dir): PharCompiler
123137 ;
124138
125139 // Command Controller 命令类不去除注释,注释上是命令帮助信息
126- $ cpr ->setStripFilter (function ($ file ) {
140+ $ compiler ->setStripFilter (function ($ file ) {
127141 /** @var \SplFileInfo $file */
128142 $ name = $ file ->getFilename ();
129143
130144 return false === strpos ($ name , 'Command.php ' ) && false === strpos ($ name , 'Controller.php ' );
131145 });
132146
133- return $ cpr ;
147+ return $ compiler ;
134148 }
135149
136150 /**
@@ -174,4 +188,4 @@ public function unpackCommand($in, $out): int
174188
175189 return 0 ;
176190 }
177- }
191+ }
0 commit comments