refactoring for dependency injection.

This commit is contained in:
Taylor Otwell 2011-08-29 22:02:32 -05:00
parent 8229891d26
commit f113b5c829
11 changed files with 23 additions and 153 deletions

View File

@ -9,11 +9,6 @@ class Arr {
* also be accessed using JavaScript "dot" style notation. Retrieving items nested
* in multiple arrays is also supported.
*
* <code>
* // Returns "taylor"
* Arr::get(array('name' => array('is' => 'Taylor')), 'name.is');
* </code>
*
* @param array $array
* @param string $key
* @param mixed $default
@ -47,11 +42,6 @@ public static function get($array, $key, $default = null)
*
* Like the Arr::get method, JavaScript "dot" syntax is supported.
*
* <code>
* // Set "name.is" to "taylor"
* Arr::set(array('name' => array('is' => 'something')), 'name.is', 'taylor');
* </code>
*
* @param array $array
* @param string $key
* @param mixed $value

View File

@ -14,14 +14,6 @@ class Config {
/**
* Determine if a configuration item or file exists.
*
* <code>
* // Determine if the "session" configuration file exists
* Config::has('session');
*
* // Determine if the application timezone option exists
* Config::has('application.timezone');
* </code>
*
* @param string $key
* @return bool
*/
@ -40,14 +32,6 @@ public function has($key)
* If the name of a configuration file is passed without specifying an item, the
* entire configuration array will be returned.
*
* <code>
* // Get the timezone option from the application configuration file
* $timezone = Config::get('application.timezone');
*
* // Get the SQLite database connection configuration
* $sqlite = Config::get('database.connections.sqlite');
* </code>
*
* @param string $key
* @param string $default
* @return array
@ -75,14 +59,6 @@ public function get($key, $default = null)
* If a specific configuration item is not specified, the entire configuration
* array will be replaced with the given value.
*
* <code>
* // Set the timezone option in the application configuration file
* Config::set('application.timezone', 'America/Chicago');
*
* // Set the session configuration array
* Config::set('session', array());
* </code>
*
* @param string $key
* @param mixed $value
* @return void

View File

@ -4,7 +4,7 @@
/*
|--------------------------------------------------------------------------
| Laravel Support Components
| Laravel Components
|--------------------------------------------------------------------------
*/
@ -59,7 +59,7 @@
'laravel.redirect' => array('singleton' => true, 'resolver' => function($container)
{
return new Redirect($container->resolve('laravel.url'));
return new Redirect($container->resolve('laravel.session.driver'), $container->resolve('laravel.url'));
}),

View File

@ -21,11 +21,6 @@ public static function container()
/**
* Magic Method for calling methods on the active container instance.
*
* <code>
* // Get the request registered in the container
* $request = IoC::resolve('laravel.request');
* </code>
*/
public static function __callStatic($method, $parameters)
{
@ -69,14 +64,6 @@ public function __construct($dependencies = array())
*
* The resolver function when the registered dependency is requested.
*
* <code>
* // Register a simple dependency
* $container->register('name', function() { return 'Fred'; });
*
* // Register a dependency as a singleton
* $container->register('name', function() { return new Name; }, true);
* </code>
*
* @param string $name
* @param Closure $resolver
* @return void
@ -89,11 +76,6 @@ public function register($name, $resolver, $singleton = false)
/**
* Determine if a dependency has been registered in the container.
*
* <code>
* // Determine if the "user" dependency is registered in the container
* $registered = $container->registered('user');
* </code>
*
* @param string $name
* @return bool
*/
@ -108,11 +90,6 @@ public function registered($name)
* Singletons will only be instantiated the first time they are resolved. On subsequent
* requests for the object, the original instance will be returned.
*
* <code>
* // Register a dependency as a singleton
* $container->singleton('user', function() { return new User; })
* </code>
*
* @param string $name
* @param Closure $resolver
* @return void
@ -128,11 +105,6 @@ public function singleton($name, $resolver)
* This method allows you to register an already existing object instance with the
* container as a singleton instance.
*
* <code>
* // Register an object instance as a singleton in the container
* $container->instance('user', new User);
* </code>
*
* @param string $name
* @param mixed $instance
* @return void
@ -147,11 +119,6 @@ public function instance($name, $instance)
*
* The dependency's resolver will be called and its result will be returned.
*
* <code>
* // Resolver the "name" dependency
* $name = $container->resolve('name');
* </code>
*
* @param string $name
* @return mixed
*/

View File

@ -17,9 +17,7 @@ public function before() {}
*/
public function __get($key)
{
$application = IoC::resolve('laravel.application');
return $application->$key;
return IoC::resolve('laravel.application')->$key;
}
/**

View File

@ -124,13 +124,6 @@ public function modified($path)
/**
* Get a file MIME type by extension.
*
* Any extension in the MIMEs configuration file may be passed to the method.
*
* <code>
* // Returns "application/x-tar"
* $mime = $file->mime('tar');
* </code>
*
* @param string $extension
* @param string $default
* @return string
@ -145,13 +138,7 @@ public function mime($extension, $default = 'application/octet-stream')
/**
* Determine if a file is a given type.
*
* The Fileinfo PHP extension will be used to determine the MIME type of the file. Any extension
* in the MIMEs configuration file may be passed as a type.
*
* <code>
* // Determine if the file is a JPG image
* $image = $file->is('jpg', 'path/to/image.jpg');
* </code>
* The Fileinfo PHP extension will be used to determine the MIME type of the file.
*
* @param string $extension
* @param string $path

View File

@ -80,14 +80,6 @@ public function has($key)
*
* This method should be used for all request methods (GET, POST, PUT, and DELETE).
*
* <code>
* // Get the "name" item from the input data
* $name = Request::active()->input->get('name');
*
* // Get the "name" item and return "Fred" if it doesn't exist.
* $name = Request::active()->input->get('name', 'Fred');
* </code>
*
* @param string $key
* @param mixed $default
* @return string
@ -111,11 +103,6 @@ public function had($key)
/**
* Get input data from the previous request.
*
* <code>
* // Get the "name" item from the old input data
* $name = Request::active()->input->old('name');
* </code>
*
* @param string $key
* @param mixed $default
* @return string
@ -132,14 +119,6 @@ public function old($key = null, $default = null)
*
* "Dot" syntax may be used to get a specific item from the file array.
*
* <code>
* // Get the array of information regarding a given file
* $file = Request::active()->input->file('picture');
*
* // Get the size of a given file
* $file = Request::active()->input->file('picture.size');
* </code>
*
* @param string $key
* @param mixed $default
* @return array
@ -165,11 +144,6 @@ public function upload($key, $path)
/**
* Magic Method for retrieving items from the request input.
*
* <code>
* // Retrieve the "name" item from the input data
* $name = Request::active()->input->name;
* </code>
*/
public function __get($key)
{

View File

@ -52,14 +52,6 @@ private function __construct($key, $replacements = array())
* Language lines are retrieved using "dot" notation. So, asking for the "messages.required" langauge
* line would return the "required" line from the "messages" language file.
*
* <code>
* // Get the "required" line from the "validation" language file
* $line = Lang::line('validation.required')->get();
*
* // Specify a replacement for a language line
* $line = Lang::line('welcome.message', array('name' => 'Fred'))->get();
* </code>
*
* @param string $key
* @param array $replacements
* @return Lang
@ -74,11 +66,6 @@ public static function line($key, $replacements = array())
*
* A default value may also be specified, which will be returned in the language line doesn't exist.
*
* <code>
* // Get a validation line and return a default value if the line doesn't exist
* $line = Lang::line('welcome.message')->get('Hello!');
* </code>
*
* @param string $language
* @return string
*/
@ -156,11 +143,6 @@ private function load($file)
*
* The language specified in this method should correspond to a language directory in your application.
*
* <code>
* // Get a "fr" language line
* $line = Lang::line('validation.required')->in('fr')->get();
* </code>
*
* @param string $language
* @return Lang
*/

View File

@ -2,15 +2,31 @@
class Redirect extends Response {
/**
* The URL generator instance.
*
* @var URL
*/
private $url;
/**
* The active session driver instance.
*
* @var Session\Driver
*/
private $session;
/**
* Create a new redirect generator instance.
*
* @param Session\Driver $session
* @param URL $url
* @return void
*/
public function __construct(URL $url)
public function __construct(Session\Driver $session, URL $url)
{
$this->url = $url;
$this->session = $session;
}
/**
@ -62,7 +78,7 @@ public function to_secure($url, $status = 302, $method = 'location')
*/
public function with($key, $value)
{
IoC::container()->resolve('laravel.session.driver')->flash($key, $value);
$this->session->flash($key, $value);
return $this;
}

View File

@ -223,14 +223,4 @@ public function status($status)
return $this;
}
/**
* Magic Method for passing undefined static methods to the Response_Factory instance
* registered in the application IoC container. This provides easy access to the
* response functions while still maintaining testability within the classes.
*/
public static function __callStatic($method, $parameters)
{
return call_user_func_array(array(IoC::container()->resolve('laravel.response'), $method), $parameters);
}
}

View File

@ -296,14 +296,4 @@ public function __unset($key)
unset($this->data[$key]);
}
/**
* Magic Method for passing undefined static methods to the View_Factory instance
* registered in the application IoC container. This provides easy access to the
* view functions while still maintaining testability within the view classes.
*/
public static function __callStatic($method, $parameters)
{
return call_user_func_array(array(IoC::container()->resolve('laravel.view'), $method), $parameters);
}
}