1. Go to this page and download the library: Download bigbit/oddin 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/ */
bigbit / oddin example snippets
class Foo {
private Dependency1 $dep1;
private Dependency2 $dep2;
private Depencency3 $dep3;
function __construct(Dependency1 $dep1, Dependency2 $dep2, Container $container)
{
$this->dep1 = $dep1;
$this->dep2 = $dep2;
$this->dep3 = $container->get(Dependency3::class);
}
public function bar()
{
$this->dep1->doSomething();
}
protected function baz()
{
$this->dep2->doSomethind();
}
private function bye()
{
$this->dep3->doSomething();
}
}
class Foo {
use InjectsOnDemand;
private Dependency1 $dep1;
private Dependency2 $dep2;
private Depencency3 $dep3;
/**
* Foo constructor.
* as of php7.4.1, we have to unset properties in constructor
* https://bugs.php.net/bug.php?id=78904
*/
public function __construct()
{
unset($this->dep1, $this->dep2, $this->dep3);
}
public function bar()
{
$this->dep1->doSomething();
}
private function baz()
{
$this->dep2->doSomething();
}
private function bye()
{
$this->dep3->doSomethind();
}
}
use BigBIT\DIBootstrap\Bootstrap;
use Psr\Container\ContainerInterface;
// custom bindings
$bindings = [
FooInterface::class => function(ContainerInterface $container) {
return new BarImplementation(
$container->get(BazDependency::class)
);
}
];
$container = Bootstrap::getContainer($bindings);
$app = new SomeApp($container);
$app->run();