Skip to content

Commit 37c422b

Browse files
Udated.!
1 parent 5be0cca commit 37c422b

File tree

3 files changed

+50
-65
lines changed

3 files changed

+50
-65
lines changed

README.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,18 @@ Or **install it manually**:
3838
| excluded | Namespace / File Paths to exclude |
3939
| fullpath | set true to provide full path |
4040

41-
### Sample Config File
42-
***class-mapper.json***
43-
```json
44-
{
45-
"namespace" : "",
46-
"source" : [ "./folder1","./folder2" ],
47-
"output" : {
48-
"location" : "mylocation/class-map-data.php",
49-
"type" : "php"
50-
},
51-
"excluded" : {
52-
"namespace" : [ "Test/ABC/"],
53-
"paths" : [ "./folder1/unwanted","./folder1/unwanted2"]
54-
},
55-
"fullpath" : false
56-
}
41+
### CMD Line
42+
```
43+
/**
44+
* Arguments Order.
45+
* 1. PHP Class Source
46+
* 2. PHP Classmap File Output
47+
* 3. Namespace (Leave Empty To Get All)
48+
* 4. exclude_namespace
49+
* 5. exclude_path
50+
* 6. fullpath
51+
*/
52+
composer classmap-generator "your-path-to-php-class" "class-map-output/files.php"
5753
```
5854

5955
## Sample Outputs

class-mapper.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{
22
"namespace" : "",
33
"source" : [ "" ],
4-
"output" : {
5-
"location" : "",
6-
"type" : "php"
7-
},
4+
"output" : "",
85
"excluded" : {
96
"namespace" : [ ],
107
"paths" : [ ]

src/generator.php

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -254,45 +254,42 @@ private static function find_classes( $path ) {
254254
}
255255
}
256256

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();
281257

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();
290280

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+
}
291289

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
296293
<?php
297294
/**
298295
* Last Updated: $last_updated
@@ -303,12 +300,7 @@ private static function find_classes( $path ) {
303300
return %s;
304301
305302
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

Comments
 (0)