so, i was asking because i often encounter myself doing things like:
IoC::register('controller_name', function()
{
return new controller_name(IoC::resolve('dependency1'), ...);
});
which is okay when you have just a few controllers, but when you have a lot, this becomes a mess.
so, i was looking for a more automatic replacement, and i found it:
Event::listen(Controller::factory, function($class)
{
$reflection = new ReflectionClass($class);
$reflectionParams = $reflection->getMethod('__construct')->getParameters();
$params = array();
foreach ( $reflectionParams as $param )
{
$params[] = IoC::resolve($param->getClass()->name);
}
return $reflection->newInstanceArgs($params);
});
(laravel 3)
greetings and thanks longilineo for your answer.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community