@@ -153,8 +153,9 @@ public function set_release(array $packages, $composer_json, $download_url, $con
153153 *
154154 * @param string $name File name
155155 * @param array $packages Packages to be dumped
156+ * @param string $subdir Optional subdirectory
156157 */
157- public function dump_include ($ name , array $ packages )
158+ public function dump_include ($ name , array $ packages, $ subdir = '' )
158159 {
159160 foreach ($ packages as $ package_name => $ versions )
160161 {
@@ -164,24 +165,27 @@ public function dump_include($name, array $packages)
164165 array ('packages ' => $ packages ),
165166 JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
166167 );
167- $ file = $ this ->build_dir . $ name ;
168+ $ target_dir = $ this ->build_dir . $ subdir ;
169+ if ($ subdir && !$ this ->fs ->exists ($ target_dir ))
170+ {
171+ $ this ->fs ->mkdir ($ target_dir );
172+ }
173+ $ file = $ target_dir . $ name ;
168174 $ this ->fs ->dumpFile ($ file , $ packages );
169175 }
170176
171177 /**
172178 * Get include files.
173179 *
174- * @param string $prefix Optional prefix to filter files
175180 * @return Finder
176181 */
177- protected function get_include_files ($ prefix = '' )
182+ protected function get_include_files ()
178183 {
179184 $ finder = new Finder ;
180- $ pattern = $ prefix ? '/^packages\- ' . preg_quote ($ prefix , '/ ' ) . '[a-z]+\-\d+\.json$/ ' : '/^packages\-[a-z]+\-\d+\.json$/ ' ;
181185 $ finder
182186 ->files ()
183187 ->depth ('== 0 ' )
184- ->name ($ pattern )
188+ ->name (' /^packages\-[a-z]+\-\d+\.json$/ ' )
185189 ->in ($ this ->build_dir )
186190 ;
187191
@@ -197,23 +201,29 @@ protected function build_parents()
197201 $ branches = ext::get_filtered_repository_branches ();
198202 foreach ($ branches as $ branch )
199203 {
200- $ this ->build_parent_structure ($ branch . '- ' );
204+ $ this ->build_parent_structure ($ branch . '/ ' );
201205 }
202206 }
203207
204208 /**
205- * Build parent structure for given prefix
209+ * Build parent structure for given subdirectory
206210 *
207- * @param string $prefix Optional prefix for files
211+ * @param string $subdir Optional subdirectory
208212 */
209- protected function build_parent_structure ($ prefix = '' )
213+ protected function build_parent_structure ($ subdir = '' )
210214 {
211- $ includes = $ this ->get_include_files ($ prefix );
215+ $ includes = $ this ->get_include_files ();
212216 $ parent = $ types = array ();
217+ $ target_dir = $ this ->build_dir . $ subdir ;
218+
219+ if ($ subdir && !$ this ->fs ->exists ($ target_dir ))
220+ {
221+ $ this ->fs ->mkdir ($ target_dir );
222+ }
213223
214224 foreach ($ includes as $ file )
215225 {
216- $ type = $ this ->get_include_type ($ file ->getFilename (), $ prefix );
226+ $ type = $ this ->get_include_type ($ file ->getFilename ());
217227
218228 if ($ type )
219229 {
@@ -229,8 +239,8 @@ protected function build_parent_structure($prefix = '')
229239
230240 foreach ($ types as $ type => $ includes )
231241 {
232- $ type_filename = $ prefix ? ' packages- ' . $ prefix . $ type . ' .json ' : 'packages- ' . $ type . '.json ' ;
233- $ type_filepath = $ this -> build_dir . $ type_filename ;
242+ $ type_filename = 'packages- ' . $ type . '.json ' ;
243+ $ type_filepath = $ target_dir . $ type_filename ;
234244 $ contents = json_encode (array ('includes ' => $ includes ));
235245 $ this ->fs ->dumpFile ($ type_filepath , $ contents );
236246
@@ -240,26 +250,23 @@ protected function build_parent_structure($prefix = '')
240250 }
241251 if (!empty ($ parent ))
242252 {
243- $ main_filename = $ prefix ? 'packages- ' . rtrim ($ prefix , '- ' ) . '.json ' : 'packages.json ' ;
244253 $ contents = json_encode (array ('includes ' => $ parent ));
245- $ this ->fs ->dumpFile ($ this -> build_dir . $ main_filename , $ contents );
254+ $ this ->fs ->dumpFile ($ target_dir . ' packages.json ' , $ contents );
246255 }
247256 }
248257
249258 /**
250259 * Get contrib type name from include file name.
251260 *
252261 * @param string $filename
253- * @param string $prefix Optional prefix to match
254262 * @return bool|string Returns contrib type name or false if not a valid filename
255263 */
256- protected function get_include_type ($ filename, $ prefix = '' )
264+ protected function get_include_type ($ filename )
257265 {
258266 $ filename = utf8_basename ($ filename );
259267 $ match = array ();
260- $ pattern = $ prefix ? '/^packages\- ' . preg_quote ($ prefix , '/ ' ) . '([a-z]+)\-\d+\.json$/ ' : '/^packages\-([a-z]+)\-\d+\.json$/ ' ;
261268
262- if (preg_match ($ pattern , $ filename , $ match ))
269+ if (preg_match (' /^packages\-([a-z]+)\-\d+\.json$/ ' , $ filename , $ match ))
263270 {
264271 return $ match [1 ];
265272 }
0 commit comments