maxbeckers/php-builder-generator

Generate builder patterns for PHP classes using attributes

1.0.1 2025-09-12 07:41 UTC

This package is auto-updated.

Last update: 2025-09-13 19:05:48 UTC


README

Generate builder patterns for PHP classes using attributes.

PHP Version License Tests

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

📚 Complete Documentation

Quick Links

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