@@ -65,15 +65,16 @@ public static function normalize_path( $path ) {
6565 * @throws \RuntimeException When the path is neither an existing file nor directory
6666 */
6767 public static function create_map ( $ path , $ args = array () ) {
68- $ args = array_merge ( array (
68+ $ args = array_merge ( array (
6969 'blacklist ' => null ,
7070 'namespace ' => null ,
7171 'excluded_paths ' => array (),
7272 'excluded_namespace ' => array (),
7373 'fullpath ' => false ,
7474 ), $ args );
75- $ blacklist = $ args ['blacklist ' ];
76- $ namespace = $ args ['namespace ' ];
75+ $ blacklist = $ args ['blacklist ' ];
76+ $ namespace = $ args ['namespace ' ];
77+ $ excluded_namespace = $ args ['excluded_namespace ' ];
7778
7879 if ( is_string ( $ path ) ) {
7980 if ( is_file ( $ path ) ) {
@@ -127,8 +128,8 @@ public static function create_map( $path, $args = array() ) {
127128 continue ;
128129 }
129130
130- if ( ! empty ( $ args [ ' excluded_namespace ' ] ) && is_array ( $ args [ ' excluded_namespace ' ] ) ) {
131- foreach ( $ args [ ' excluded_namespace ' ] as $ nspace ) {
131+ if ( ! empty ( $ excluded_namespace ) && is_array ( $ excluded_namespace ) ) {
132+ foreach ( $ excluded_namespace as $ nspace ) {
132133 if ( ! empty ( $ nspace ) && 0 === strpos ( $ class , $ nspace ) ) {
133134 $ failed = true ;
134135 break ;
@@ -263,14 +264,14 @@ private static function find_classes( $path ) {
263264 * 6. fullpath
264265 */
265266
266- $ last_updated = date ( 'D d-M-Y / h:i:s:a ' );
267+ $ last_updated = date ( 'D d-M-Y | h:i:s:a ' );
267268$ cgf = array (
268269 'namespace ' => ( isset ( $ argv [3 ] ) ) ? $ argv [3 ] : '' ,
269270 'source ' => ( isset ( $ argv [1 ] ) ) ? $ argv [1 ] : '' ,
270271 'output ' => ( isset ( $ argv [2 ] ) ) ? $ argv [2 ] : '' ,
271272 'exclude_namespace ' => ( isset ( $ argv [4 ] ) ) ? $ argv [4 ] : '' ,
272273 'exclude_path ' => ( isset ( $ argv [5 ] ) ) ? $ argv [5 ] : '' ,
273- 'fullpath ' => ( isset ( $ argv [6 ] ) && ! empty ( $ argv [6 ] ) ) ? true : false ,
274+ 'fullpath ' => ( isset ( $ argv [6 ] ) && ! empty ( $ argv [6 ] ) ),
274275);
275276$ cgf ['source ' ] = ( ! is_array ( $ cgf ['source ' ] ) ) ? explode ( ', ' , $ cgf ['source ' ] ) : $ cgf ['source ' ];
276277$ cgf ['exclude_namespace ' ] = ( ! is_array ( $ cgf ['exclude_namespace ' ] ) ) ? explode ( ', ' , $ cgf ['exclude_namespace ' ] ) : $ cgf ['exclude_namespace ' ];
@@ -286,20 +287,24 @@ private static function find_classes( $path ) {
286287 ) ) );
287288}
288289
289- $ total = count ( $ maps );
290- $ namespace = $ cgf ['namespace ' ];
290+ $ headers = implode ( PHP_EOL , array_filter ( array (
291+ '// Last Updated: ' . date ( 'D d-M-Y | h:i:s:a ' ),
292+ '// Total Class: ' . count ( $ maps ),
293+ ( ! empty ( $ cgf ['namespace ' ] ) ) ? '// Namespace: ' . $ cgf ['namespace ' ] : null ,
294+ ) ) );
295+
291296$ contents = <<<PHP
292297<?php
293- /**
294- * Last Updated: $ last_updated
295- * Total Class: $ total
296- * Namespace: $ namespace
297- */
298+ $ {headers}
298299
299300return %s;
300301
301302PHP ;
302303$ path_info = pathinfo ( $ cgf ['output ' ] );
303- $ save_data = ( 'json ' === $ path_info ['extension ' ] ) ? json_encode ( $ maps ) : var_export ( $ maps , true );
304+ if ( 'json ' === $ path_info ['extension ' ] ) {
305+ $ save_data = json_encode ( $ maps );
306+ } else {
307+ $ save_data = var_export ( $ maps , true );
308+ }
304309$ save_data = ( 'json ' === $ path_info ['extension ' ] ) ? $ save_data : sprintf ( $ contents , $ save_data );
305310file_put_contents ( $ cgf ['output ' ], $ save_data );
0 commit comments