more dependency injection!

This commit is contained in:
Taylor Otwell
2011-08-31 00:07:45 -05:00
parent c200f3eb1e
commit c7ddbbb018
20 changed files with 118 additions and 223 deletions

View File

@@ -1,29 +1,37 @@
<?php namespace Laravel;
class Application {
abstract class Resolver {
/**
* The application IoC container.
* Magic Method for resolving classes out of the IoC container.
*
* This allows the derived class to provide access to all of the Laravel libraries
* registered in the container. Currently, this class is derived by the Application
* and Controller classes.
*/
public function __get($key)
{
if (IoC::container()->registered('laravel.'.$key))
{
return IoC::container()->resolve('laravel.'.$key);
}
elseif (IoC::container()->registered($key))
{
return IoC::container()->resolve($key);
}
throw new \Exception("Attempting to access undefined property [$key].");
}
}
class Application extends Resolver {
/**
* The IoC container instance for the application.
*
* @var Container
*/
public $container;
/**
* Magic Method for resolving core classes out of the IoC container.
*/
public function __get($key)
{
if ($this->container->registered('laravel.'.$key))
{
return $this->container->resolve('laravel.'.$key);
}
elseif ($this->container->registered($key))
{
return $this->container->resolve($key);
}
throw new \Exception("Attempting to access undefined property [$key] on application instance.");
}
}