Welcome to the PHP Builder Generator documentation! This library automatically generates builder patterns for your PHP classes — as a dev-only dependency.
PHP Builder Generator is a Composer plugin that creates builder classes for your PHP objects at build time. Configuration lives in a single php-builder-generator.php file in your project root — your production classes stay completely clean, with no dependency on this library.
php-builder-generator.php config file// php-builder-generator.php
use MaxBeckers\PhpBuilderGenerator\Config\PhpBuilderGeneratorConfig;
return PhpBuilderGeneratorConfig::configure()
->scanDirectory('src/Model');
// src/Model/User.php — no imports from this library!
class User
{
public function __construct(
public string $name,
public string $email,
public ?int $age = null
) {}
}
// Generated builder usage:
$user = UserBuilder::builder()
->name('John Doe')
->email('john@example.com')
->age(30)
->build();
php-builder-generator.php referenceReady to get started? Check out the Quick Start Guide!