{"id":15543526,"url":"https://github.com/michaeluno/php-classmap-generator","last_synced_at":"2025-08-20T09:08:04.785Z","repository":{"id":62528124,"uuid":"234905597","full_name":"michaeluno/php-classmap-generator","owner":"michaeluno","description":"Generates class maps of specified directories.","archived":false,"fork":false,"pushed_at":"2022-02-22T16:57:17.000Z","size":99,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-03T12:30:41.684Z","etag":null,"topics":["autoload","class-file","class-file-list","class-file-map-generator","class-map","class-map-generator","file-list","file-list-generator","file-map-generator","library","php","php-library"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michaeluno.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-19T13:33:18.000Z","updated_at":"2022-02-17T11:33:28.000Z","dependencies_parsed_at":"2022-11-02T16:15:40.042Z","dependency_job_id":null,"html_url":"https://github.com/michaeluno/php-classmap-generator","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeluno%2Fphp-classmap-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeluno%2Fphp-classmap-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeluno%2Fphp-classmap-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeluno%2Fphp-classmap-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michaeluno","download_url":"https://codeload.github.com/michaeluno/php-classmap-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246121767,"owners_count":20726819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autoload","class-file","class-file-list","class-file-map-generator","class-map","class-map-generator","file-list","file-list-generator","file-map-generator","library","php","php-library"],"created_at":"2024-10-02T12:27:25.018Z","updated_at":"2025-03-29T00:29:31.697Z","avatar_url":"https://github.com/michaeluno.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Class Map Generator\nA PHP class that generates class maps for autoload.\n\n## Installation\n### Composer\nTo install the library using Composer, run \n\n```bash\ncomposer require michaeluno/php-classmap-generator\n```\n\n## Usage\nInstantiate the class with options.\n\n```php\nnew \\PHPClassMapGenerator\\PHPClassMapGenerator(\n    __DIR__,                        // base dir\n    __DIR__ . '/_scandir',          // scan dir path\n    __DIR__ . '/class-map.php',     // the result output file\n);\n```\n\nThis creates a class map file looking like a following.\n```php\n\u003c?php \n$aClassMap = array( \n    \"Foo\\FooClass\" =\u003e CLASS_MAP_BASE_DIR_VAR . \"/_scandir/FooClass.php\", \n    \"Foo\\FooClass_Base\" =\u003e CLASS_MAP_BASE_DIR_VAR . \"/_scandir/FooClass_Base.php\", \n    \"Joe\\JoeInterface\" =\u003e CLASS_MAP_BASE_DIR_VAR . \"/_scandir/interfaces/JoeInterface.php\", \n    \"Bar\\Bar\" =\u003e CLASS_MAP_BASE_DIR_VAR . \"/_scandir/traits/BarTrait.php\", \n);\n```\n\nBefore including the map file, define the constant `CLASS_MAP_BASE_DIR_VAR` in your PHP script. \n\n```php\n    define( 'CLASS_MAP_BASE_DIR_VAR', __DIR__ );\n``` \nor whatever the base directory path should be.\n\nThis automatically inserted string `CLASS_MAP_BASE_DIR_VAR` can be changed to whatever string you need with the option argument `base_dir_var`. For more details, see the 4th parameter section. \n\nInterfaces and traits are also included.\n\n### Parameters\nThe class accepts four parameters.\n\n#### 1. (string) Base Directory Path\nThe first parameter accepts the base directory path. \n\nThis is required because scanned and gathered absolute paths are on the system where the script runs. However, the actual users of your programs do not share the same absolute paths depending on their systems. That's why the base directory path will be replaced with a constant or a variable in the output.    \n\n#### 2. (string|array) Scan Directory Paths\nThe second parameter accepts directory paths to scan. For multiple paths, pass an numerically indexed array holding them.\n\n##### Examples\n```php\nnew \\PHPClassMapGenerator\\PHPClassMapGenerator(\n    __DIR__,                        \n    __DIR__ . '/scandir',         \n    __DIR__ . '/class-map.php',     \n);\n```\n\n```php\nnew \\PHPClassMapGenerator\\PHPClassMapGenerator(\n    __DIR__,                        \n    [ __DIR__ . '/scandir', __DIR__ . '/scandir2' ],         \n    __DIR__ . '/class-map.php',     \n);\n```\n\n#### 3. (string) The output PHP file path.\nSet a path that the generated list will be written.\n\n#### 4. Options (optional)\nThis parameter accepts an array holding options.\n\n - `output_buffer`\t\t: (boolean)\twhether output buffer should be printed.     \n - `exclude_classes` \t: (array)   an array holding class names to exclude.\n - `base_dir_var`\t\t: (string)\tthe variable or constant name that is prefixed before the inclusion path. Default: `__DIR__`.\n - `output_var_name`\t: (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. \n - `do_in_constructor`  : (boolean) whether to perform the action in the constructor. Default: `true`.\n - `structure`          : (string) either `CLASS` or `PATH`. When `CLASS` is set, the generated array keys consist of class names. When `PATH` is set, the generated array keys consist of paths. Default: `CLASS`.\n - `short_array_syntax` : (boolean) whether to use `array()` or `[]` for array declaration. `true` for `[]`. Default: `false`.\n - `search`\t\t\t\t: (array)\tthe arguments for the directory search options.\n    - `allowed_extensions`: (array) allowed file extensions to be listed. e.g. `[ 'php', 'inc' ]` \n    - `exclude_dir_paths`: (array) directory paths to exclude from the list.  \n    - `exclude_dir_names`: (array) directory base names to exclude from the list. e.g. `[ 'temp', '_bak', '_del', 'lib', 'vendor', ]` \n    - `exclude_file_names`: (array) a sub-string of file names to exclude from the list. e.g. `[ '.min' ]` \n    - `exclude_substrings`: (array) sub-strings of paths to exclude from the list. e.g. `[ '.min', '_del', 'temp', 'library', 'vendor' ]`\n    - `is_recursive`: (boolean) whether to scan sub-directories.\n    - `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' ]`,   \n - `comment_header`  : (array, optional)   what header comment to insert at the top of the generated file\n    - `text`  : (string, optional) the header comment to set    \n    - `path`  : (string, optional) the file path to extract the comment from\n    - `class` : (string, optional) the class name to use its doc-block as the header comment\n    - `type`  : (string, optional) indicates what type of data to collect. Accepted values are `DOCBLOCK`, `CONSTANT`. \n##### Example\n\n##### Generating a class map in the script directory.     \n```php\nnew \\PHPClassMapGenerator\\PHPClassMapGenerator(\n    dirname( __DIR__ ),\n    [ __DIR__ . '/includes', ],\n    __DIR__ . '/class-map.php', \n    [       \n        'output_buffer'      =\u003e true,\n        'exclude_classes'    =\u003e [ 'TestClass' ],        \n        'output_var_name'   =\u003e '$classMap',\n        'base_dir_var'      =\u003e '\\MyProject\\Registry::$dirPath',\n        'search'            =\u003e [\n            'allowed_extensions'    =\u003e [ 'php' ],\n            'exclude_dir_paths'     =\u003e [ __DIR__ . '/includes/class/admin' ],\n            'exclude_dir_names'     =\u003e [ '_del', '_bak' ],\n            'exclude_file_names'    =\u003e [ 'test.php', 'uninsall.php' ],\n            'is_recursive'          =\u003e true,\n        ],\n    ]\n);\n``` \n\n##### Do not write to a file\n```php\n$_oGenerator = new \\PHPClassMapGenerator\\PHPClassMapGenerator(\n    __DIR__,                        // base dir\n    __DIR__ . '/_scandir',          // scan dir name\n    __DIR__ . '/class-map.php',\n    [\n        'do_in_constructor'     =\u003e false,\n    ]\n);\nprint_r( $_oGenerator-\u003eget() );\n``` \n\n#### Find CSS files\n```php\n$_oGenerator = new \\PHPClassMapGenerator\\PHPClassMapGenerator(\n    __DIR__,                        // base dir\n    __DIR__ . '/_scandir',          // scan dir name\n    __DIR__ . '/class-map.php',\n    [\n        'output_var_name'\t\t=\u003e 'return',\n        'do_in_constructor'     =\u003e false,\n        'structure'             =\u003e 'PATH',\n        'search'                =\u003e [\n            'allowed_extensions'     =\u003e [ 'css' ],\n            'ignore_note_file_names' =\u003e [ 'ignore-css-map.txt' ],\n            'exclude_file_names'     =\u003e [ '.min.' ],\n        ],\n    ]\n);\n\nprint_r( $_oGenerator-\u003eget() );\n```\nTo find JavaScript files, change the `'css'` part to `'js'` in the `allowed_extensions` search argument.\n \n## Bundled Utility Autoloader\nThis package includes an autoloader.\n\n### Examples\n#### Including an array of class list\n```\n$_aClassMap = [\n  \"PHPClassMapGenerator\\\\PHPClassMapGenerator\" =\u003e __DIR__ . \"/PHPClassMapGenerator.php\",\n  \"PHPClassMapGenerator\\\\Autoload\" =\u003e __DIR__ . \"/autoload.php\",\n];\nPHPClassMapGenerator\\Utility\\Autoload::set( $_aClassMap );\n```\n\n#### Including the class map file that returns an array of class list\n```\nPHPClassMapGenerator\\Utility\\Autoload::set( include( __DIR__ . '/class-map.php' ) );\n```\n\n ## License\n Licensed under [MIT](./LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaeluno%2Fphp-classmap-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaeluno%2Fphp-classmap-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaeluno%2Fphp-classmap-generator/lists"}