PHP code example of talesoft / tale-factory

1. Go to this page and download the library: Download talesoft/tale-factory library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

talesoft / tale-factory example snippets


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!"