PHP code example of bizley / deep-instantiate

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

    

bizley / deep-instantiate example snippets


class Alpha implements AlphaInterface
{
    private $beta;

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

class Beta implements BetaInterface
{
}

class Gamma
{
    private $alpha;

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

$container->set(BetaInterface::class, Beta::class);
$alpha = $container->get(Alpha::class);

$alpha = $container->get(Alpha::class, [Beta::class]);

$container->set(AlphaInterface::class, Alpha::class);
$container->set(BetaInterface::class, Beta::class);
$gamma = $container->get(Gamma::class);

$gamma = $container->get(Gamma::class, [
    [
        'class' => Alpha::class,
        '__construct()' => Beta::class
    ]
]);