-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add optional params to make()
method
#12
Conversation
Signed-off-by: Fery Wardiyanto <ferywardiyanto@gmail.com>
Signed-off-by: Fery Wardiyanto <ferywardiyanto@gmail.com>
Signed-off-by: Fery Wardiyanto <ferywardiyanto@gmail.com>
NoteThe array of second arguments will only be passed to callback method not the class constructor. $container->make(SomeClass::class, ['value']); // returns 'value'
class SomeClass
{
// The $param will call $container->get('param')
public function __construct($param) {}
// The $param will get 'value'
public function __invoke($param) {
return $param
}
}
$container->make('AnotherClass::theMethod', ['value']); // returns 'value', OR
$container->make(['AnotherClass', 'theMethod'], ['value']); // returns 'value'
class AnotherClass
{
// The $param will call $container->get('param')
public function __construct($param) {}
// The $param will get 'value'
public function theMethod($param) {
return $param
}
} If the 1st param is not callable or conditionally call a method from 3rd param, the array parameter will be ignored and // The 'value' will be ignored since this class doesn't have `__invoke` method.
$container->make(SomeClass::class, ['value']); // returns instance of SomeClass
class SomeClass
{
// The $param will remain call $container->get('param')
public function __construct($param) {}
public function someMethod($param) {
return $param
}
} |
Signed-off-by: Fery Wardiyanto <ferywardiyanto@gmail.com>
Signed-off-by: Fery Wardiyanto <ferywardiyanto@gmail.com>
Signed-off-by: Fery Wardiyanto <ferywardiyanto@gmail.com>
If the 1st param is a closure, the 2nd param will passed to the callback container/test/spec/Container.spec.php Lines 241 to 243 in b685fde
Unless it overrided by the 3rd param container/test/spec/Container.spec.php Lines 245 to 253 in b685fde
|
Add ability to optionally pass additional params to its callback and throws
InvalidArgumentException
if it was invalid, obviously.Specs:
container/test/spec/Container.spec.php
Lines 185 to 189 in 512222e
container/test/spec/Container.spec.php
Lines 213 to 217 in 512222e
make()
container/test/spec/Container.spec.php
Lines 203 to 207 in 512222e