natitech/builder-generator

PHP standalone library to generate a builder (pattern) from a class

1.4.0 2019-09-09 04:23 UTC

This package is auto-updated.

Last update: 2020-07-09 06:28:44 UTC


README

Build Status License

PHP standalone library to generate a builder pattern from a class.

Installation

By using composer on your project or globally

composer require natitech/builder-generator
composer global require natitech/builder-generator

Usage

You can use the binary to generate a builder near a class :

./vendor/bin/generate-builder

OR you can use it inside another PHP script :

\Nati\BuilderGenerator\FileBuilderGenerator::create()->generateFrom('/path/to/entity');

What will be generated

This will generate a Builder class aside the built class.

The generated file may need to receive updates on codestyle, faker usages, infered types, etc.

To avoid producing unused code, there are no setters for builder properties. Your IDE should be able to easily generate them.

The generator supports many stategies to write property values : public, setter, constructor. But you have to be consistent across the built class. The most used strategy inside the built class will be used for the entire builder class.

IDE / PHPStorm

You can use this tool as an external tool in your IDE.

For PHPStorm user, see https://www.jetbrains.com/help/phpstorm/configuring-third-party-tools.html. Example configuration :

  • Name : Generate builder
  • Description : Generate a builder class from a PHP class
  • Program [if global installation, fix full path] : /path/to/your/home/.composer/vendor/bin/generate-builder
  • Arguments : $FilePath$
  • Working directory : $FileDir$