everton3x/autoload-files-plugin
最新稳定版本:v1.0.0
Composer 安装命令:
composer require everton3x/autoload-files-plugin
包简介
README 文档
README
A Composer plugin to automatically load all PHP files from specified directories into the autoload.files configuration. Perfect for projects with helper files, legacy code, or configuration scripts.
✨ Features
- Auto-include PHP files: Automatically adds all
.phpfiles from configured directories to Composer's autoload. - Directory scanning: Supports nested directories (recursive scanning).
- Symfony Finder integration: Efficient file discovery with the Symfony Finder component.
- Composer event-driven: Hooks into Composer's
pre-autoload-dumpevent.
🚀 Installation
Install via Composer:
composer require everton3x/autoload-files-plugin`
🛠️ Usage
- Configure Directories
Add your target directories to composer.json under the extra section:
{
"extra": {
"autoload-files-from": [
"src/Helpers",
"config/scripts",
"legacy"
]
}
}
- Run Composer
Update and regenerate the autoloader:
composer update composer dump-autoload
All PHP files in the specified directories will now be autoloaded!
🔍 How It Works
The plugin:
Listens to Composer's pre-autoload-dump event
Scans all directories listed in extra.autoload-files-from
Adds every found .php file to autoload.files
Updates Composer's autoload configuration
📂 Example Structure
my-project/
├── src/
│ └── Helpers/
│ ├── StringHelper.php
│ └── ArrayHelper.php
├── config/
│ └── scripts/
│ └── bootstrap.php
Result:
// vendor/composer/autoload_files.php return [ // ... 'a1b2c3' => $baseDir . '/src/Helpers/StringHelper.php', 'd4e5f6' => $baseDir . '/src/Helpers/ArrayHelper.php', 'g7h8i9' => $baseDir . '/config/scripts/bootstrap.php', ];
⚠️ Notes
Performance: Avoid very large directories (1000+ files) as this may slow down Composer operations.
Duplicates: Files already listed in autoload.files will not be added twice.
Alternatives: For class-based autoloading, prefer psr-4 or classmap.
🤝 Contributing
Fork the repository
Create a feature branch (git checkout -b feature/awesome-feature)
Commit changes (git commit -am 'Add awesome feature')
Push to branch (git push origin feature/awesome-feature)
Open a Pull Request
📄 License
MIT License. See LICENSE for details.
Happy autoloading! 🎉 Created with ❤️ for PHP developers
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2025-05-22