@@ -36,6 +36,7 @@ public function configure()
3636 ->setHelp ('PHP Code compiler - Phar executable compiling utility ' )
3737 ->addOption ('main ' , 'e ' , Option::VALUE , 'Set the PHAR stub \'s main entrypoint script ' )
3838 ->addOption ('dir ' , 'd ' , Option::MULTI , 'Add directory contents ("-d $dir") optionally filtered on a specific file extension ("$dir:$extension") ' )
39+ ->addOption ('file ' , 'f ' , Option::MULTI , 'Add a single file to the archive ' )
3940 ->addOption ('output ' , 'o ' , Option::VALUE , 'Set the compiled archive output name ' )
4041 ->addOption ('banner ' , 'b ' , Option::VALUE , 'Load legal notice from the given banner file ' )
4142 ;
@@ -49,11 +50,14 @@ public function execute()
4950 $ banner = $ this ->getOption ('banner ' ) ?? '' ;
5051
5152 $ dirs = $ this ->getOption ('dir ' ) ?? [];
53+ $ files = $ this ->getOption ('file ' ) ?? [];
54+
5255 $ output = $ this ->getOption ('output ' );
5356 $ main = $ this ->getOption ('main ' );
5457
5558 $ this
5659 ->initBuilder ($ main )
60+ ->addFiles ($ files )
5761 ->addDirectories ($ dirs )
5862 ->setNotice ($ banner )
5963 ->publish ($ output )
@@ -96,7 +100,7 @@ protected function addDirectory(string $directory, string $extensions = null)
96100 /**
97101 * Add a single file to the archive builder
98102 *
99- * @param string $file
103+ * @param string $file A relative or absolute file path
100104 *
101105 */
102106 protected function addFile (string $ file )
@@ -110,7 +114,7 @@ protected function addFile(string $file)
110114 /**
111115 * Add a list of directory specifications to the archive builder
112116 *
113- * @param array $dirs A list of directories in the form "$dir" or "$dir:$extension"
117+ * @param string[] $dirs A list of specs in the form "$dir" or "$dir:$extension"
114118 *
115119 * @return self
116120 */
@@ -120,14 +124,31 @@ protected function addDirectories(array $dirs): self
120124 list ($ directory , $ extensions ) = explode (': ' , $ spec );
121125
122126 $ wildcard = $ extensions ? "*. $ extensions " : 'all ' ;
123- $ this ->info ("Scanning directory <strong> $ directory</strong> for <strong> $ wildcard</strong> files ... " );
127+ $ this ->info ("Scanning directory <strong> $ directory</strong> for <strong> $ wildcard</strong> files... " );
124128
125129 $ this ->addDirectory ($ directory , $ extensions );
126130 }
127131
128132 return $ this ;
129133 }
130134
135+ /**
136+ * Add a list of single files to the archive builder
137+ *
138+ * @param string[] $files A list of relative or absolute file paths
139+ *
140+ * @return self
141+ */
142+ protected function addFiles (array $ files ): self
143+ {
144+ foreach ($ files as $ file ) {
145+ $ this ->info ("Adding single file <strong> $ file</strong>... " );
146+ $ this ->addFile ($ file );
147+ }
148+
149+ return $ this ;
150+ }
151+
131152 /**
132153 * Add banner file contents to the archive builder
133154 *
@@ -138,7 +159,7 @@ protected function addDirectories(array $dirs): self
138159 protected function setNotice (string $ banner = null ): self
139160 {
140161 if (is_file ($ banner )) {
141- $ this ->info ("Loading banner contents from <strong> $ banner</strong> file ... " );
162+ $ this ->info ("Loading banner contents from <strong> $ banner</strong> file... " );
142163 $ contents = file_get_contents ($ banner );
143164 $ header = $ this ->phpdocize ($ contents );
144165
@@ -159,7 +180,7 @@ protected function setNotice(string $banner = null): self
159180 */
160181 protected function publish (string $ output , string $ compression = 'GZ ' ): self
161182 {
162- $ this ->info ("Writing Phar archive to <strong> $ output</strong> ... " );
183+ $ this ->info ("Writing Phar archive to <strong> $ output</strong>... " );
163184 $ this ->builder ->compile ($ output , $ compression );
164185
165186 return $ this ;
0 commit comments