library tale-factory
A small and lightweight implementation of the factory pattern
talesoft/tale-factory
A small and lightweight implementation of the factory pattern
- Saturday, May 21, 2016
- by TorbenKoehn
- Repository
- 3 Watchers
- 0 Stars
- 17,234 Installations
- PHP
- 5 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 2 Versions
- 8 % Grown
Tale Factory
What is Tale Factory?
A generic implementation of the factory pattern., (*1)
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., (*2)