Too few arguments to function {closure}(), 0 passed and exactly 1 expected
burzum opened this issue · comments
Too few arguments to function {closure}(), 0 passed and exactly 1 expected
So why am I getting the error for this? I've checked a few tickets but couldn't really figure out why this won't work for me. We are using version 3.2.
use League\Container\Container;
$container = new Container();
$container->add('app.database.connection.default', function () {
return new \PDO('mysql:dbname=test', '', '');
});
$container->add(\App\Infrastructure\Authentication\ServiceProvider::class, function($container) {
return new \App\Infrastructure\Authentication\ServiceProvider($container->get('app.database.connection.default'));
});
$container->add(\Phauthentic\Authentication\AuthenticationServiceProviderInterface::class, \App\Infrastructure\Authentication\ServiceProvider::class);
$container->get(\App\Infrastructure\Authentication\ServiceProvider::class);
Hi, when resolving definitions via a closure you're in control about what is passed to the closure as you won't always need the container.
If you change the code above to this it should work fine.
$container->add(\App\Infrastructure\Authentication\ServiceProvider::class, function($container) {
return new \App\Infrastructure\Authentication\ServiceProvider($container->get('app.database.connection.default'));
})->addArgument($container);