2017 © Pedro PelĂĄez
 

library php-object-builder

PHP 7+ Object Builder

image

lgse/php-object-builder

PHP 7+ Object Builder

  • Thursday, September 7, 2017
  • by l0gicgate
  • Repository
  • 2 Watchers
  • 2 Stars
  • 36 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

PHP Object Builder

https://github.com/lgse/php-object-builder, (*1)

PHP 7+ Recursive Object Builder, (*2)

About

PHP Object Builder will validate instantiate recursively all of your complex objects by passing in an array of values., (*3)

Features

  • Validates argument types
  • Passes arguments to constructors in the right order
  • Instantiates parameter classes
  • Lightning Fast
  • Easy to use

Install

composer require php-object-builder

Usage

use PHPOB\Model;
use PHPOB\ObjectBuilder;

/**
 * Example Object Class To Instantiate
 * Extending our `Model` class will add the `getInstance` static method
 * to your object so you don't have to create an object builder every
 * time you want to instantiate a class.
 */
class Customer extends Model {
    public function __construct(
        int $id,
        string $name,
        Address $address
    ) {
        $this->id = $id;
        $this->name = $name;
        $this->address = $address;
    }
    ...
}
class Address {
    public function __construct(
        string $street,
        string $city,
        string $state,
        int $zip
    ) {
        $this->street = $street;
        $this->city = $city;
        $this->state = $state;
        $this->zip = $zip;
    }
    ...
}

/**
 * Example instantiation using the `getInstance` static method
 */
$customer = Customer::getInstance([
    'id' => '0e2c0f21-2c46-4cf9-ad7e-2beeadb9282b',
    'name' => 'Microsoft',
    'address' => [
        'street' => '1 Microsoft Way',
        'city' => 'Redmond',
        'state' => 'WA',
        'zip' => 98052,
    ]
]);

/**
 * Example instantiation using the object builder
 * Note: You can pass in instantiated parameters that will be automatically passed through
 * to the object's constructor
 */
 $builder = new ObjectBuilder(Customer::class);
 $customer = $builder->getObject([
    'id' => '0e2c0f21-2c46-4cf9-ad7e-2beeadb9282b',
    'name' => 'Microsoft',
    'address' => new Address([
        'street' => '1 Microsoft Way',
        'city' => 'Redmond',
        'state' => 'WA',
        'zip' => 98052,
    ])
 ]);

API

Available methods for Model:

  • static getInstance(array|object $arguments) Automatically creates a builder object and returns an instance of extended class.

Available methods for ObjectBuilder:

  • __construct(string $className) Instantiates a builder object for provided class name.
  • getObject(array $arguments) Returns an instantiated object using an array of arguments.

The Versions

07/09 2017

dev-master

9999999-dev https://github.com/lgse/php-object-builder

PHP 7+ Object Builder

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Pierre Bérubé

object builder

07/09 2017

v1.6

1.6.0.0 https://github.com/lgse/php-object-builder

PHP 7+ Object Builder

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Pierre Bérubé

object builder

01/09 2017

v1.5

1.5.0.0 https://github.com/lgse/php-object-builder

PHP 7+ Object Builder

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Pierre Bérubé

object builder

01/09 2017

v1.4

1.4.0.0 https://github.com/lgse/php-object-builder

PHP 7+ Object Builder

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Pierre Bérubé

object builder

13/07 2017

v1.3

1.3.0.0 https://github.com/lgse/php-object-builder

PHP 7+ Object Builder

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Pierre Bérubé

object builder

13/07 2017

v1.2

1.2.0.0 https://github.com/lgse/php-object-builder

PHP 7+ Object Builder

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Pierre Bérubé

object builder

11/06 2017

v1.1

1.1.0.0 https://github.com/lgse/php-object-builder

PHP 7+ Object Builder

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Pierre Bérubé

object builder

05/06 2017

v1.0

1.0.0.0 https://github.com/lgse/php-object-builder

PHP 7+ Object Builder

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Pierre Bérubé

object builder