Skip to content

Commit 2079235

Browse files
committed
- Moved the source files into source.
- Supported return instead of assigning the generated map array into a variable.
1 parent 194cab9 commit 2079235

10 files changed

+49
-33
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ This parameter accepts an array holding options.
7171
- `output_buffer` : (boolean) whether or not output buffer should be printed.
7272
- `exclude_classes` : (array) an array holding class names to exclude.
7373
- `base_dir_var` : (string) the variable or constant name that is prefixed before the inclusion path.
74+
- `output_var_name` : (string) The variable string that the map array is assigned to. Default: `$aClassMap`. If `return` is set, the variable will not be set but the file just returns the generated map array.
7475
- `search` : (array) the arguments for the directory search options.
7576
- `allowed_extensions`: (array) allowed file extensions to be listed.
7677
- `exclude_dir_paths`: (array) directory paths to exclude from the list.

composer.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33
"description": "A PHP class that generates class maps for autoload.",
44
"minimum-stability": "stable",
55
"license": "MIT",
6+
"type": "library",
67
"authors": [
78
{
89
"name": "Michael Uno",
910
"email": "michael2@michaeluno.jp"
1011
}
11-
]
12+
],
13+
"require": {
14+
"php": ">=5.6.20"
15+
},
16+
"autoload": {
17+
"psr-4": {"PHPClassMapGenerator": "source/"}
18+
}
1219
}
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ class PHPClassMapGenerator extends PHPClassMapGenerator_Base {
2525

2626
static protected $_aStructure_Options = array(
2727

28-
'header_class_name' => '',
29-
'header_class_path' => '',
30-
'output_buffer' => true,
31-
'header_type' => 'DOCBLOCK',
32-
'exclude_classes' => array(),
33-
'base_dir_var' => 'CLASS_MAP_BASE_DIR_VAR',
34-
'output_var_name' => '$aClassMap',
28+
'header_class_name' => '',
29+
'header_class_path' => '',
30+
'output_buffer' => true,
31+
'header_type' => 'DOCBLOCK',
32+
'exclude_classes' => array(),
33+
'base_dir_var' => 'CLASS_MAP_BASE_DIR_VAR',
34+
'output_var_name' => '$aClassMap',
3535

3636
// Search options
3737
'search' => array(
@@ -115,7 +115,14 @@ public function __construct( $sBaseDirPath, $asScanDirPaths, $sOutputFilePath, a
115115
}
116116

117117
// 4. Write to a file
118-
$this->___write( $_aFiles, $sBaseDirPath, $sOutputFilePath, $_sHeaderComment, $aOptions[ 'output_var_name' ], $aOptions[ 'base_dir_var' ] );
118+
$this->___write(
119+
$_aFiles,
120+
$sBaseDirPath,
121+
$sOutputFilePath,
122+
$_sHeaderComment,
123+
$aOptions[ 'output_var_name' ],
124+
$aOptions[ 'base_dir_var' ]
125+
);
119126

120127
}
121128

@@ -154,7 +161,9 @@ private function ___write( array $aFiles, $sBaseDirPath, $sOutputFilePath, $sHea
154161
$_aData[] = mb_convert_encoding( '<?php ' . PHP_EOL . $sHeadingComment, 'UTF-8', 'auto' );
155162

156163
// Start array declaration
157-
$_aData[] = $sOutputArrayVar . ' = array( ' . PHP_EOL;
164+
$_aData[] = 'return' === $sOutputArrayVar
165+
? 'return array( ' . PHP_EOL
166+
: $sOutputArrayVar . ' = array( ' . PHP_EOL;
158167

159168
// Insert the data
160169
$sBaseDirVar = $sBaseDirVar ? $sBaseDirVar : '""';
File renamed without changes.

test/class-map.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
$aClassMap = array(
2+
return array(
33
"Foo\FooClass" => CLASS_MAP_BASE_DIR_VAR . "/_scandir/FooClass.php",
44
"Foo\FooClass_Base" => CLASS_MAP_BASE_DIR_VAR . "/_scandir/FooClass_Base.php",
55
"Joe\JoeInterface" => CLASS_MAP_BASE_DIR_VAR . "/_scandir/interfaces/JoeInterface.php",

test/generate-map-_scandir.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
include( dirname( __DIR__ ) . '/PHPClassMapGenerator.php' );
4-
5-
3+
include( dirname( __DIR__ ) . '/source/PHPClassMapGenerator.php' );
64

75

86
new \PHPClassMapGenerator\PHPClassMapGenerator(
97
__DIR__, // base dir
108
__DIR__ . '/_scandir', // scan dir name
119
__DIR__ . '/class-map.php',
12-
[]
10+
[
11+
'output_var_name' => 'return',
12+
]
1313
);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
include( dirname( __DIR__ ) . '/source/PHPClassMapGenerator.php' );
4+
5+
6+
new \PHPClassMapGenerator\PHPClassMapGenerator(
7+
dirname( __DIR__ ) . '/source', // base dir
8+
dirname( __DIR__ ) . '/source', // scan dir name
9+
dirname( __DIR__ ) . '/source/class-map.php',
10+
[
11+
'base_dir_var' => '__DIR__',
12+
'search' => [
13+
'exclude_dir_names' => [ 'test' ],
14+
]
15+
]
16+
);

test/generate-this-project-class-map.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

test/test-autoload.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<?php
22

33
define( 'CLASS_MAP_BASE_DIR_VAR', __DIR__ );
4-
include( __DIR__ . '/class-map.php' );
54

65

7-
\Autoload::set( $aClassMap );
6+
\Autoload::set( include( __DIR__ . '/class-map.php' ) );
87

98
$_o = new \Foo\FooClass;
109
var_dump( get_class( $_o ) );

0 commit comments

Comments
 (0)