-
-
Save willemwollebrants/87ad60d2ed5579c5c70f022fa005f88b to your computer and use it in GitHub Desktop.
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 | |
$examples = new League\Container\Container(); | |
class NonInvokableExample | |
{ | |
} | |
class InvokableExample | |
{ | |
public function __invoke() | |
{ | |
return 'a value'; | |
} | |
} | |
$examples->add("InvokableAsClassname", InvokableExample::class); | |
$examples->add("InvokableAsClosure", function() { | |
return new InvokableExample(); | |
}); | |
$examples->add("InvokableAsInstance", new InvokableExample()); | |
var_dump($examples->get("InvokableAsClassname")); | |
//returns object(InvokableExample) | |
var_dump($examples->get("InvokableAsClosure")); | |
//returns object(InvokableExample) | |
var_dump($examples->get("InvokableAsInstance")); | |
//returns string 'a value' | |
$examples->add("NonInvokableAsClassname", NonInvokableExample::class); | |
$examples->add("NonInvokableAsClosure", function() { | |
return new NonInvokableExample(); | |
}); | |
$examples->add("NonInvokableAsInstance", new NonInvokableExample()); | |
var_dump($examples->get("NonInvokableAsClassname")); | |
//returns object(NonInvokableExample) | |
var_dump($examples->get("NonInvokableAsClosure")); | |
//returns object(NonInvokableExample) | |
var_dump($examples->get("NonInvokableAsInstance")); | |
//returns object(NonInvokableExample) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment