PHP standalone library to generate a builder (pattern) from a class
PHP standalone library to generate a builder pattern from a class.
By using composer on your project or globally
composer require natitech/builder-generator composer global require natitech/builder-generator
You can use the binary to generate a builder near a class :
OR you can use it inside another PHP script :
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.
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$