PHP code example of gacela-project / container

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

    

gacela-project / container example snippets


$bindings = [
  AbstractString::class => StringClass::class,
  ClassInterface::class => new ConcreteClass(/* args */),
  ComplexInterface::class => new class() implements Foo {/** logic */},
  FromCallable::class => fn() => new StringClass('From callable'),
];

$container = new Container($bindings);

$instance = $container->get(YourClass::class);

//////////////////////////////////////////////
# Extra: you can resolve closures on-the-fly using the container bindings
$resolved = $container->resolve(function (ComplexInterface $i) {
    // your custom logic
    return $i->...; 
});