Commit 8ba0dfac authored by Taylor Otwell's avatar Taylor Otwell

refactoring controller __get magic method ioc resolution.

parent bcb6f189
...@@ -90,20 +90,17 @@ abstract class Controller { ...@@ -90,20 +90,17 @@ abstract class Controller {
/** /**
* Dynamically resolve items from the application IoC container. * Dynamically resolve items from the application IoC container.
* *
* First, "laravel." will be prefixed to the requested item to see if there is * <code>
* a matching Laravel core class in the IoC container. If there is not, we will * // Retrieve an object registered in the container as "mailer"
* check for the item in the container using the name as-is. * $mailer = $this->mailer;
*
* // Equivalent call using the IoC container instance
* $mailer = IoC::container()->resolve('mailer');
* </code>
*/ */
public function __get($key) public function __get($key)
{ {
if (IoC::container()->registered("laravel.{$key}")) if (IoC::container()->registered($key)) return IoC::container()->resolve($key);
{
return IoC::container()->core($key);
}
elseif (IoC::container()->registered($key))
{
return IoC::container()->resolve($key);
}
throw new \Exception("Attempting to access undefined property [$key] on controller."); throw new \Exception("Attempting to access undefined property [$key] on controller.");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment