talesoft/tale-factory

A generic factory implementation

0.3 2019-01-20 16:53 UTC

This package is auto-updated.

Last update: 2024-11-21 20:33:18 UTC


README

What is Tale Factory?

A generic implementation of the factory pattern.

Installation

composer require talesoft/tale-factory

Usage

use Tale\Factory;

interface AdapterInterface
{
    public function sayHello(): void;
}

class TestAdapter
{
    private $message;
    
    public function __construct(string $message)
    {
        $this->message = $message;
    }
    
    public function sayHello(): void
    {
        echo $this->message;
    }
}

$factory = new Factory(
    AdapterInterface::class,
    ['Hello from adapter!'],
    [
        'test' => TestAdapter::class
    ]
);


$instance = $factory->get('test');
$instance->sayHello(); //"Hello from adapter!"

TODO: More docs.