Projectsphp-builderInstallation

PHP Builder

Package

A PHP code builder for programmatically generating classes, interfaces, traits, and enums.

Installation

Requirements

The package is framework-agnostic. Laravel is only used in the test suite.

Install

composer require bradietilley/php-builder

There is no service provider to register and no config to publish — the package works as soon as it is autoloaded.

Verifying the install

use BradieTilley\Builder\PhpClass;
use BradieTilley\Builder\PhpMethod;

$php = (new PhpClass(
    namespace: 'App\\Support',
    name: 'Hello',
    methods: [
        new PhpMethod(
            name: 'greet',
            return: 'string',
            lines: ["return 'hi';"],
        ),
    ],
))->toPhp();

// Starts with "<?php" and contains "class Hello"

Namespace

All public types live under BradieTilley\Builder (and BradieTilley\Builder\Types for the type system, BradieTilley\Builder\Support for imports and other helpers).

Next steps