maxbeckers/php-builder-generator
最新稳定版本:1.1.4
Composer 安装命令:
composer require maxbeckers/php-builder-generator
包简介
Generate builder patterns for PHP classes using attributes
README 文档
README
Generate builder patterns for PHP classes using attributes.
Features
- 🚀 Attribute-based: Use PHP attributes to mark classes for builder generation
- 🏃 Zero Runtime Overhead: Builders generated at build time, not runtime
- 📝 IDE Friendly: Full autocomplete and type checking support
- 🔧 Highly Configurable: Customize every aspect of generation
- 🎯 Type Safe: Preserves all type information from original classes
- 🏗️ Constructor Aware: Intelligently handles constructor parameters
Quick Start
1. Install
composer require maxbeckers/php-builder-generator
2. Configure Composer
Add to your composer.json:
{
"config": {
"allow-plugins": {
"maxbeckers/php-builder-generator": true
}
}
}
3. Update Autoload for Generated Builders
{
"autoload": {
"psr-4": {
"App\\": ["src/", "generated/php-builder-generator/App/"]
}
}
}
Important: The path must include the namespace (e.g. .../App/), not just the base output directory.
After updating, run:
composer dump-autoload
4. Add Builder Attribute
<?php namespace App\Model; use MaxBeckers\PhpBuilderGenerator\Attributes\Builder; #[Builder] class User { public function __construct( public string $name, public string $email, public ?int $age = null, public array $roles = [] ) {} }
5. Generate & Use
Builders are automatically generated during composer install/update, or run:
./vendor/bin/php-builder-generator
Use your generated builder:
$user = UserBuilder::builder() ->name('John Doe') ->email('john@example.com') ->age(30) ->roles(['admin']) ->build();
Documentation
Quick Links
- Installation & Setup - Detailed installation guide
- Basic Usage - Learn the fundamentals
- Configuration Guide - All configuration options
- Basic Examples - Common use cases
- Contributing - How to contribute
Requirements
- PHP 8.2 or higher
- Composer 2.0 or higher
Show Your Support
If you find this package helpful, I would be happy to get a ⭐ star on GitHub! It helps others discover the project and motivates continued development.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Questions or Issues? Please open an issue on GitHub.
Built with ❤️ for PHP developers
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-11