@@ -20,34 +20,34 @@ Dependency Injection Container
2020class Foo // Has dependencies
2121{
2222 protected $bar;
23- protected $anotherClass ;
23+ protected $fooBar ;
2424 protected $name;
2525
26- public function __construct(Bar $bar, $name)
26+ public function __construct(Bar $bar, $name='Sohel Amin', $param2=null) // Dependency Injected
2727 {
2828 $this->bar = $bar;
2929 $this->name = $name;
3030 }
3131
32- public function setterMethod(AnotherClass $anotherClass)
32+ public function setterMethod(FooBar $fooBar) // Dependency Injected on method
3333 {
34- return $this->anotherClass = $anotherClass ;
34+ return $this->fooBar = $fooBar ;
3535 }
3636}
3737
38- class FooBar { } // No dependencies
38+ class Bar { } // No dependencies
3939
40- class AnotherClass { } // No dependencies
40+ class FooBar { } // No dependencies
4141
4242
4343// Instantiate the container
44- $container = Container::getInstance();
44+ $container = Appzcoder\Container\ Container::getInstance();
4545
4646// Registering class with dependencies
4747$container->make('Foo');
4848
4949// Registering class with another name
50- $container->make('foo', 'Foo ');
50+ $container->make('foo', 'Bar ');
5151
5252// Binding a closure object with a name
5353$container->make('FooBar', function () {
@@ -61,7 +61,7 @@ $container->make('Foo', 'Foo', ['param 1', 'param 2']);
6161$instance = new FooBar();
6262$container->instance('FooBar', $instance);
6363
64- // Binding an instance/orbject with container's array
64+ // Binding an instance/object with container's array
6565$container['FooBar'] = new FooBar();
6666
6767// Calling a setter method with dependencies
0 commit comments