Skip to content

Commit ed81615

Browse files
committed
Added the ignore_note_file_names search argument.
1 parent 42c2b2a commit ed81615

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,15 @@ This parameter accepts an array holding options.
7171
- `output_buffer` : (boolean) whether 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.
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.
75+
- `do_in_constructor` : (boolean) whether to perform the action in the constructor. Default: `true`.
7576
- `search` : (array) the arguments for the directory search options.
7677
- `allowed_extensions`: (array) allowed file extensions to be listed.
7778
- `exclude_dir_paths`: (array) directory paths to exclude from the list.
7879
- `exclude_dir_names`: (array) directory base names to exclude from the list.
7980
- `exclude_file_names`: (array) file names (with extension) to exclude from the list.
80-
- `is_recursive`: (boolean) whether to scan sub-directories.
81+
- `is_recursive`: (boolean) whether to scan sub-directories.
82+
- `ignore_note_file_names`: (array) ignore note file names that tell the parser to skip the directory. When one of the files exist in the parsing directory, the directory will be skipped. Default: `[ 'ignore-class-map.txt' ]`,
8183

8284
##### Example
8385
```php

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Change Log
22

33
## 1.1.0 - 2020/09/14
4+
- Added the `ignore_note_file_names` search argument.
5+
- Added the `do_in_constructor` argument.
46
- Supported no namespace classes.
57

68
## 1.0.1 - 2020/01/20

source/PHPClassMapGenerator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ class PHPClassMapGenerator extends PHPClassMapGenerator_Base {
6161
'allowed_extensions' => array( 'php' ), // e.g. array( 'php', 'inc' )
6262
'exclude_dir_paths' => array(),
6363
'exclude_dir_names' => array(),
64+
'exclude_file_names' => array(), // 1.0.3+ includes an file extension.
6465
'is_recursive' => true,
66+
'ignore_note_file_names' => array( 'ignore-class-map.txt' ) // 1.1.0 When this option is present and the parsing directory contains a file matching one of the set names, the directory will be skipped.
6567
),
6668

6769
);
@@ -178,8 +180,8 @@ protected function _do() {
178180
* @since 1.1.0
179181
*/
180182
protected function _getOptionsFormatted( array $aOptions ) {
181-
$aOptions = $aOptions + self::$_aStructure_Options;
182-
$aOptions[ 'search' ] = $aOptions[ 'search' ] + self::$_aStructure_Options[ 'search' ];
183+
$aOptions = $aOptions + self::$_aStructure_Options + parent::$_aStructure_Options;
184+
$aOptions[ 'search' ] = $aOptions[ 'search' ] + self::$_aStructure_Options[ 'search' ] + parent::$_aStructure_Options[ 'search' ];
183185
return $aOptions;
184186
}
185187

source/PHPClassMapGenerator_Base.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ public function __construct() {
3333

3434
// Search options
3535
'search' => array(
36-
'allowed_extensions' => array( 'php' ), // e.g. array( 'php', 'inc' )
37-
'exclude_dir_paths' => array(),
38-
'exclude_dir_names' => array(), // the directory 'base' name
39-
'exclude_file_names' => array(), // 1.0.3+ includes an file extension.
40-
'is_recursive' => true,
36+
'allowed_extensions' => array( 'php' ), // e.g. array( 'php', 'inc' )
37+
'exclude_dir_paths' => array(),
38+
'exclude_dir_names' => array(), // the directory 'base' name
39+
'exclude_file_names' => array(), // 1.0.3+ includes an file extension.
40+
'is_recursive' => true,
41+
'ignore_note_file_names' => array( 'ignore-class-map.txt' ) // 1.1.0 When this option is present and the parsing directory contains a file matching one of the set names, the directory will be skipped.
4142
),
4243

4344
'carriage_return' => PHP_EOL,
@@ -128,11 +129,34 @@ protected function _formatPaths( $asDirPaths ) {
128129
protected function _getPathFormatted( $sPath ) {
129130
return rtrim( str_replace( '\\', '/', $sPath ), '/' );
130131
}
132+
133+
134+
/**
135+
* Checks whether a file exists.
136+
*
137+
* @remark Checks all the paths given as array members and at least one of them exists, the method returns true.
138+
* @param array $aFilePaths
139+
* @param string $sSuffix The path suffix to prepend to the path set in the array.
140+
* @return bool
141+
*/
142+
private function ___fileExists( array $aFilePaths, $sSuffix='' ) {
143+
foreach( $aFilePaths as $_sFilePath ) {
144+
if ( file_exists( $sSuffix . $_sFilePath ) ) {
145+
return true;
146+
}
147+
}
148+
return false;
149+
}
150+
131151
/**
132152
* The recursive version of the glob() function.
133153
*/
134154
private function ___doRecursiveGlob( $sPathPatten, $nFlags=0, array $aExcludeDirPaths=array(), array $aExcludeDirNames=array(), array $aExcludeFileNames=array() ) {
135155

156+
if ( $this->___fileExists( $aIgnoreNotes, dirname( $sPathPatten ) . '/' ) ) {
157+
return array();
158+
}
159+
136160
$_aFiles = glob( $sPathPatten, $nFlags );
137161
$_aFiles = is_array( $_aFiles ) ? $_aFiles : array(); // glob() can return false.
138162
$_aFiles = $this->___dropExcludingFiles( $_aFiles, $aExcludeFileNames );

0 commit comments

Comments
 (0)