maxbeckers / php-builder-generator
Generate builder patterns for PHP classes using attributes
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 1
Forks: 0
Open Issues: 0
Type:composer-plugin
Requires
- php: ^8.2
- composer-plugin-api: ^2.0
- symfony/console: ^6.0|^7.0
- symfony/finder: ^6.0|^7.0
- twig/twig: ^3.0
Requires (Dev)
- composer/composer: ^2.0
- phpunit/phpunit: ^10.0
- symfony/filesystem: ^6.0|^7.0
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 --dev
2. Configure Composer
Add to your composer.json
:
{ "config": { "allow-plugins": { "maxbeckers/php-builder-generator": true } } }
3. 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 = [] ) {} }
4. 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 - Get started in 5 minutes
- 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