PHP code example of cviniciussdias / dependency-resolver

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

    

cviniciussdias / dependency-resolver example snippets



use CViniciusSDias\DependencyResolver\Resolver;

// Classes definitions
class Class1
{
    private $class2;

    public function __construct(Class2 $class, Class3 $class3)
    {
        echo $class3->method();
        $this->class2 = $class;
    }

    public function test()
    {
        echo $this->class2;
    }
}

class Class2
{
    public function __construct(Class3 $test, $param = 'default value')
    {
        echo $param . PHP_EOL;
    }

    public function __toString()
    {
        return 'Class2::__toString()';
    }
}

class Class3
{
    public function __construct($paramWithoutDefaulValue)
    {
    }

    public function method()
    {
        return 'Class3::method()' . PHP_EOL;
    }
}

// Resolver usage
$resolver = new Resolver();
$resolver->setParameters(Class3::class, ['paramWithoutDefaulValue' => 'manual value']);
$class1 = $resolver->resolve(Class1::class);
$class1->test();