@@ -254,45 +254,42 @@ private static function find_classes( $path ) {
254
254
}
255
255
}
256
256
257
- $ config_file = ( isset ( $ argv [1 ] ) ) ? $ argv [1 ] : false ;
258
- if ( ! empty ( $ config_file ) && file_exists ( $ config_file ) ) {
259
- $ cgf = file_get_contents ( $ config_file );
260
- if ( ! empty ( $ cgf ) ) {
261
- $ cgf = json_decode ( $ cgf , true );
262
- $ cgf = array_merge ( array (
263
- 'namespace ' => '' ,
264
- 'source ' => '' ,
265
- 'output ' => array (),
266
- 'excluded ' => array (),
267
- 'fullpath ' => false ,
268
- ), $ cgf );
269
- $ cgf ['excluded ' ] = array_merge ( array (
270
- 'namespace ' => '' ,
271
- 'paths ' => '' ,
272
- ), $ cgf ['excluded ' ] );
273
- $ cgf ['output ' ] = array_merge ( array (
274
- 'location ' => '' ,
275
- 'type ' => '' ,
276
- ), $ cgf ['output ' ] );
277
- $ cgf ['source ' ] = ( ! is_array ( $ cgf ['source ' ] ) ) ? explode ( ', ' , $ cgf ['source ' ] ) : $ cgf ['source ' ];
278
- $ cgf ['excluded ' ]['namespace ' ] = ( ! is_array ( $ cgf ['excluded ' ]['namespace ' ] ) ) ? explode ( ', ' , $ cgf ['excluded ' ]['namespace ' ] ) : $ cgf ['excluded ' ]['namespace ' ];
279
- $ cgf ['excluded ' ]['paths ' ] = ( ! is_array ( $ cgf ['excluded ' ]['paths ' ] ) ) ? explode ( ', ' , $ cgf ['excluded ' ]['paths ' ] ) : $ cgf ['excluded ' ]['paths ' ];
280
- $ maps = array ();
281
257
282
- foreach ( $ cgf ['source ' ] as $ path ) {
283
- $ maps = array_merge ( $ maps , ClassMapGenerator::create_map ( $ path , array (
284
- 'excluded_paths ' => $ cgf ['excluded ' ]['paths ' ],
285
- 'excluded_namespace ' => $ cgf ['excluded ' ]['namespace ' ],
286
- 'namespace ' => $ cgf ['namespace ' ],
287
- 'fullpath ' => $ cgf ['fullpath ' ],
288
- ) ) );
289
- }
258
+ /**
259
+ * 1. PHP Class Source
260
+ * 2. PHP Classmap File Output
261
+ * 3. Namespace (Leave Empty To Get All)
262
+ * 4. exclude_namespace
263
+ * 5. exclude_path
264
+ * 6. fullpath
265
+ */
266
+
267
+ $ last_updated = date ( 'D d-M-Y / h:i:s:a ' );
268
+ $ cgf = array (
269
+ 'namespace ' => ( isset ( $ argv [3 ] ) ) ? $ argv [3 ] : '' ,
270
+ 'source ' => ( isset ( $ argv [1 ] ) ) ? $ argv [1 ] : '' ,
271
+ 'output ' => ( isset ( $ argv [2 ] ) ) ? $ argv [2 ] : '' ,
272
+ 'exclude_namespace ' => ( isset ( $ argv [4 ] ) ) ? $ argv [4 ] : '' ,
273
+ 'exclude_path ' => ( isset ( $ argv [5 ] ) ) ? $ argv [5 ] : '' ,
274
+ 'fullpath ' => ( isset ( $ argv [6 ] ) && ! empty ( $ argv [6 ] ) ) ? true : false ,
275
+ );
276
+ $ cgf ['source ' ] = ( ! is_array ( $ cgf ['source ' ] ) ) ? explode ( ', ' , $ cgf ['source ' ] ) : $ cgf ['source ' ];
277
+ $ cgf ['exclude_namespace ' ] = ( ! is_array ( $ cgf ['exclude_namespace ' ] ) ) ? explode ( ', ' , $ cgf ['exclude_namespace ' ] ) : $ cgf ['exclude_namespace ' ];
278
+ $ cgf ['exclude_path ' ] = ( ! is_array ( $ cgf ['exclude_path ' ] ) ) ? explode ( ', ' , $ cgf ['exclude_path ' ] ) : $ cgf ['exclude_path ' ];
279
+ $ maps = array ();
290
280
281
+ foreach ( $ cgf ['source ' ] as $ path ) {
282
+ $ maps = array_merge ( $ maps , ClassMapGenerator::create_map ( $ path , array (
283
+ 'excluded_paths ' => $ cgf ['exclude_path ' ],
284
+ 'excluded_namespace ' => $ cgf ['exclude_namespace ' ],
285
+ 'namespace ' => $ cgf ['namespace ' ],
286
+ 'fullpath ' => $ cgf ['fullpath ' ],
287
+ ) ) );
288
+ }
291
289
292
- $ last_updated = date ( 'D d-M-Y / h:i:s:a ' );
293
- $ total = count ( $ maps );
294
- $ namespace = $ cgf ['namespace ' ];
295
- $ contents = <<<PHP
290
+ $ total = count ( $ maps );
291
+ $ namespace = $ cgf ['namespace ' ];
292
+ $ contents = <<<PHP
296
293
<?php
297
294
/**
298
295
* Last Updated: $ last_updated
@@ -303,12 +300,7 @@ private static function find_classes( $path ) {
303
300
return %s;
304
301
305
302
PHP ;
306
- $ save_data = ( 'json ' === $ cgf ['output ' ]['type ' ] ) ? json_encode ( $ maps ) : var_export ( $ maps , true );
307
- $ save_data = ( 'json ' === $ cgf ['output ' ]['type ' ] ) ? $ save_data : sprintf ( $ contents , $ save_data );
308
- file_put_contents ( $ cgf ['output ' ]['location ' ], $ save_data );
309
- } else {
310
- echo 'Config File Read Error! ' ;
311
- }
312
- } else {
313
- echo 'Classmap Config File Not Exists ' ;
314
- }
303
+ $ path_info = pathinfo ( $ cgf ['output ' ] );
304
+ $ save_data = ( 'json ' === $ path_info ['extension ' ] ) ? json_encode ( $ maps ) : var_export ( $ maps , true );
305
+ $ save_data = ( 'json ' === $ path_info ['extension ' ] ) ? $ save_data : sprintf ( $ contents , $ save_data );
306
+ file_put_contents ( $ cgf ['output ' ], $ save_data );
0 commit comments