Created
June 18, 2017 17:42
-
-
Save devmsh/8be183f5dc8aa656c3809e17cb164ad2 to your computer and use it in GitHub Desktop.
simple IoC challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class B | |
{ | |
} | |
class A | |
{ | |
private $b; | |
function __construct(B $b) | |
{ | |
$this->b = $b; | |
} | |
} | |
class Container | |
{ | |
public static function make($className) | |
{ | |
// TODO: enhance the make function code | |
return new $className(); | |
} | |
} | |
$b = Container::make(B::class); // no problem | |
$a = Container::make(A::class); // Too few arguments exception |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment