Download the PHP package xoubaman/builder without Composer

On this page you can find all versions of the php package xoubaman/builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package builder

Builder

A PHP library to simplify the implementation of builders.

The builder pattern is a design pattern where a class know how to build another one. Using builders provides a number of benefits:

Here you have a post outlining these benefits more in detail.

Installation

Require the dependency in your project using composer:

composer require --dev xoubaman/builder

Tests are the most common place for using builders. If you intend to use the library outside tests, do not include the --dev flag.

Using a builder

Builders define a "base" setup in the property $base that will be used as a starting point for each build. This initial setup can be modified to build customized instances.

Once you have a builder prepared it will provide the following public methods:

Creating builders with the CLI generator

Since builders boilerplate is a repetitive and non-sexy thing to write, a generator script is provided to automatically create builders for a provided class.

The script requires the fully qualified name of the class as a parameter:

vendor/bin/builder build "Game\MetalSlugCharacter"

Will create the Game\MetalSlugCharacterBuilder.

It is possible to use a custom template for the builders instead of the one provided. For that a converter must be passed as a parameter:

vendor/bin/builder build "Game\MetalSlugCharacter" "Path\To\My\Converter"

A converter is a class implementing the Converter interface. It will be invoked by the script passing Xoubaman\Builder\Generator\ClassMetadata\ClassMetadata as parameter.

Creating builders manually

Tips and tricks

The following protected methods are available to create custom methods to modify the build setup:

The magic method __call is implemented in a way that calling a withParameter method will attempt to replace they key parameter in the current setup. For instance, withFooBar('baz') will set the key fooBar in the current setup with the value 'baz'.

For better typing it is a good idea to override the build method in the child builder setting the return type to the class being instantiated.

Any value in $base property (or the current setup) that is a callable will be called when building. For instance, with $base['foo' => function() { return 'bar'; }], the value used for parameter foo will be 'bar'. This is useful to yield different values on each build, like some autoincremental id.

Example

The following is an example of a builder, quite similar to what the generator will create:

Now, in our tests:

Adding more swag

For builder setups used over and over again, encapsulate that setup in a static factory method to remove duplication and improve readability. This is a design pattern called Object Mother:

If your builder + mother became too cluttered consider separating them, using the builder internally inside the mother.

License

This library is licensed under MIT License. More details in LICENSE file.


All versions of builder with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
roave/better-reflection Version ^3.5
symfony/console Version ^4.3 || ^5.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package xoubaman/builder contains the following files

Loading the files please wait ....