2017 © Pedro Peláez
 

library simple-factory

Mini-package implementing and providing a Simple Factory (design pattern) functionality.

image

da2e/simple-factory

Mini-package implementing and providing a Simple Factory (design pattern) functionality.

  • Sunday, May 21, 2017
  • by dmitrya2e
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Da2e SimpleFactory

Build Status, (*1)

SimpleFactory is a mini-package implementing Simple Factory design pattern and providing its functionality., (*2)

How to use

<?php

use Da2e\SimpleFactory\SimpleFactory;

$factory = new SimpleFactory();
$factory->create(TheObjectYouNeedToCreate::class, ['optional', 'array', 'of', 'constructor', 'args']);

The order of the constructor arguments matters!, (*3)

To automate the process of creating homogeneous objects with the same constructor arguments, you could simply create a wrapper for the SimpleFactory and pass the required arguments to its constructor, as follows:, (*4)

<?php

use Da2e\SimpleFactory\SimpleFactory;

class MySimpleFactory extends SimpleFactory
{
    private $dependency;

    public function __construct($dependency)
    {
        $this->dependency = $dependency;
    }

    /**
     * {@inheritdoc}
     */
    public function create(string $class, array $constructorArgs = [])
    {
        parent::create($class, array_merge([$this->dependency], $constructorArgs));
    }
}

$factory = new MySimpleFactory('foobar');
$factory->create(TheObjectYouNeedToCreate1::class);
$factory->create(TheObjectYouNeedToCreate2::class);
$factory->create(TheObjectYouNeedToCreate3::class);

Software requirements

  • PHP >= 7.0

How to install

composer require da2e/simple-factory "1.*"

License

This bundle is under the MIT license., (*5)

The Versions

21/05 2017

dev-master

9999999-dev

Mini-package implementing and providing a Simple Factory (design pattern) functionality.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Dmitry Abrosimov

php code pattern simple factory design

21/05 2017

v1.0.0

1.0.0.0

Mini-package implementing and providing a Simple Factory (design pattern) functionality.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Dmitry Abrosimov

php code pattern simple factory design