PHP code example of php-packages / container

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

    

php-packages / container example snippets


class A
{
}

get_class(container()->make("A")); # => "A"
get_class(container()->make(new A)); # => "A"

class B
{

    public function __construct(array $foo = [], A $bar)
    {
        var_dump($foo); # => []
        get_class($bar); # => "A"
    }
}

container()->make("B");

class C
{

    public function __construct(array $foo)
    {
        var_dump($foo); # => [1, 2, "C"]
    }
}

container()->make("C", [[1, 2, raw("C")]]);

class C
{
}

class A
{

    /**
     * @shouldBeInjected
     * @var C
     */
    public $b;
}

get_class(container()->inject(new A)->b); # => "C"

container()->bind("foo", "stdClass");
container()->bind("bar", $bar = new stdClass);

var_dump(container()->make("foo")); # => an instance of stdClass
var_dump(container()->make("bar") === container()->make("bar")); # => true
shell
composer