Support the ongoing development of →
IOC Architecture Testing
Last updated 1 year ago.

I prefer facades

Last updated 1 year ago.

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.

Last updated 1 year ago.

Sign in to participate in this thread!


Your banner here too?

Ruk33 ruk33 Joined 9 Feb 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.