PHP code example of yiisoft / factory

1. Go to this page and download the library: Download yiisoft/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/ */

    

yiisoft / factory example snippets


$container = new PSR11DependencyInjectionContainer();
$factoryConfig = [
    EngineInterface::class => [
        'class' => EngineMarkOne::class,
        '__construct()' => [
            'power' => 42,
        ],
    ]
];

$factory = new Factory($container, $factoryConfig);

$one = $factory->create(EngineInterface::class);
$two = $factory->create([
    'class' => EngineInterface::class,
    '__construct()' => [
        'power' => 146,
    ],
]);

$factory = new Factory($container, $factoryConfig, false);