Download the PHP package runopencode/abstract-builder without Composer

On this page you can find all versions of the php package runopencode/abstract-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 abstract-builder

Abstracr builder

Packagist Scrutinizer Code Quality Code Coverage Build Status Build Status

SensioLabsInsight

If you intend to use builder pattern in your project (see article on Wikipedia) you can use a prototype implementation of builder pattern from this library.

In order to do so, you have to create your own builder class, extend RunOpenCode\AbstractBuilder\AbstractBuilder and implement methods configureParameters and getObjectFqcn.

For those extra lazy developers, there is a RunOpenCode\AbstractBuilder\ReflectiveAbstractBuilder as well, which implements configureParameters method by introspecting constructor parameters and default values.

NOTE: Builder class MUST NOT validate provided parameters. Class which ought to be builded must do such validation, because construction process of any instance of any class must be valid whether is executed with or without builder implementation.

Implementation example

Let's say that we have some class Message for which we have to provide a builder class. Here is how to do so:

<?php

class Message
{
    private $id;
    private $message;
    private $timestamp;

    public function __construct($id, $message, $timestamp)
    {
        $this->id = $id;
        $this->message = $message;
        $this->timestamp = $timestamp;
    }
}

final class MessageBuilder extends \RunOpenCode\AbstractBuilder\AbstractBuilder
{
    /**
     * Get builded message.
     *
     * Alias to \RunOpenCode\AbstractBuilder\AbstractBuilder::build() method.
     *
     * @see \RunOpenCode\AbstractBuilder\AbstractBuilder::build()
     *
     * @return object
     */
    public function getMessage()
    {
        return $this->build();
    }

    /**
     * {@inheritdoc}
     */
    protected function configureParameters()
    {
        return array(
            'id' => null,
            'message' => null,
            'timestamp' => new \DateTime('now')
        );
    }

    /**
     * {@inheritdoc}
     */
    protected function getObjectFqcn()
    {
        return Message::class;
    }
}

Builder usage example

Start with creating a builder, you can use plain constructor:

$builder = new MessageBuilder();

or you can use a static method for that:

$builder = MessageBuilder::create();

You can get/set each individual configured builder property via:

Property access:

$builder->id = 1;
$id = $builder->id;

Setter method:

$builder->setId(1);
$id = $builder->getId();

Array access:

$builder['id'] = 1;
$id = $builder['id'];

Multiple properties, via array:

$builder->fromArray([ 'id' => 1, 'message' => 'Some message' ]);
$allProperties = $builder->toArray();
$someProperties = $builder->toArray([ 'id', 'message' ]);

And finaly, you can build conrete object by calling build() method, or invoking builder as method:

$message = $builder->build();
$message = $builder();

Chaining (fluent interface)

Fluent interface is supported for setter methods, so you can chain them, example:

$message = MessageBuilder::create()
                ->setId(1)
                ->setMessage('Some message')
                ->setTimestamp(new \DateTime('now'))
                ->build();

All versions of abstract-builder with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
roave/security-advisories Version dev-master
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 runopencode/abstract-builder contains the following files

Loading the files please wait ....