refactoring various classes.
This commit is contained in:
parent
c3f5abc37a
commit
32391b7f32
|
@ -13,11 +13,14 @@ class IoC {
|
|||
* Get the active container instance.
|
||||
*
|
||||
* The container is set early in the request cycle and can be access here for
|
||||
* use as a service locator if dependency injection is not practical.
|
||||
* use as a service locator if object injection is not practical.
|
||||
*
|
||||
* <code>
|
||||
* // Get the active container instance
|
||||
* $container = IoC::container();
|
||||
*
|
||||
* // Get the active container instance and call the resolve method
|
||||
* $instance = IoC::container()->resolve('instance');
|
||||
* $container = IoC::container()->resolve('instance');
|
||||
* </code>
|
||||
*
|
||||
* @return Container
|
||||
|
@ -73,15 +76,15 @@ public function __construct($registry = array())
|
|||
}
|
||||
|
||||
/**
|
||||
* Register a dependency and its resolver.
|
||||
* Register an object and its resolver.
|
||||
*
|
||||
* The resolver function is called when the registered dependency is requested.
|
||||
* The resolver function is called when the registered object is requested.
|
||||
*
|
||||
* <code>
|
||||
* // Register a dependency in the container
|
||||
* // Register an object in the container
|
||||
* IoC::register('something', function($container) {return new Something;});
|
||||
*
|
||||
* // Register a dependency in the container as a singleton
|
||||
* // Register an object in the container as a singleton
|
||||
* IoC::register('something', function($container) {return new Something;}, true);
|
||||
* </code>
|
||||
*
|
||||
|
@ -95,7 +98,7 @@ public function register($name, $resolver, $singleton = false)
|
|||
}
|
||||
|
||||
/**
|
||||
* Determine if a dependency has been registered in the container.
|
||||
* Determine if an object has been registered in the container.
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
|
@ -106,13 +109,13 @@ public function registered($name)
|
|||
}
|
||||
|
||||
/**
|
||||
* Register a dependency as a singleton.
|
||||
* Register an object as a singleton.
|
||||
*
|
||||
* 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 in the container as a singleton
|
||||
* // Register an object in the container as a singleton
|
||||
* IoC::singleton('something', function($container) {return new Something;});
|
||||
* </code>
|
||||
*
|
||||
|
@ -129,13 +132,11 @@ public function singleton($name, $resolver)
|
|||
* Register an instance as a singleton.
|
||||
*
|
||||
* This method allows you to register an already existing object instance with the
|
||||
* container as a singleton instance.
|
||||
* container to be managed as a singleton instance.
|
||||
*
|
||||
* <code>
|
||||
* // Register an instance with the IoC container
|
||||
* $something = new Something;
|
||||
*
|
||||
* IoC::instance('something', $something);
|
||||
* IoC::instance('something', new Something);
|
||||
* </code>
|
||||
*
|
||||
* @param string $name
|
||||
|
@ -148,12 +149,14 @@ public function instance($name, $instance)
|
|||
}
|
||||
|
||||
/**
|
||||
* Resolve a dependency.
|
||||
* Resolve an object.
|
||||
*
|
||||
* The dependency's resolver will be called and its result will be returned.
|
||||
* The object's resolver will be called and its result will be returned. If the
|
||||
* object is registered as a singleton and has already been resolved, the instance
|
||||
* that has already been instantiated will be returned.
|
||||
*
|
||||
* <code>
|
||||
* // Get the "something" dependency out of the IoC container
|
||||
* // Get the "something" object out of the IoC container
|
||||
* $something = IoC::resolve('something');
|
||||
* </code>
|
||||
*
|
||||
|
|
|
@ -9,6 +9,13 @@ class Cookie {
|
|||
*/
|
||||
protected $cookies;
|
||||
|
||||
/**
|
||||
* The cookies that will be sent to the browser at the end of the request.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $queue = array();
|
||||
|
||||
/**
|
||||
* Create a new cookie manager instance.
|
||||
*
|
||||
|
@ -38,7 +45,7 @@ public function has($name)
|
|||
* // Get the value of a cookie
|
||||
* $value = Cookie::get('color');
|
||||
*
|
||||
* // Get the value of a cookie and return "blue" if the cookie doesn't exist
|
||||
* // Get the value of a cookie or return a default value
|
||||
* $value = Cookie::get('color', 'blue');
|
||||
* </code>
|
||||
*
|
||||
|
@ -99,7 +106,22 @@ public function put($name, $value, $minutes = 0, $path = '/', $domain = null, $s
|
|||
|
||||
$time = ($minutes != 0) ? time() + ($minutes * 60) : 0;
|
||||
|
||||
return setcookie($name, $value, $time, $path, $domain, $secure, $http_only);
|
||||
$this->queue[] = compact('name', 'value', 'time', 'path', 'domain', 'secure', 'http_only');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send all of the cookies in the queue to the browser.
|
||||
*
|
||||
* This method is called automatically at the end of every request.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
foreach ($this->queue as $cookie)
|
||||
{
|
||||
call_user_func_array('setcookie', $cookie);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -346,11 +346,6 @@ private function list_elements($type, $list, $attributes = array())
|
|||
/**
|
||||
* Build a list of HTML attributes from an array.
|
||||
*
|
||||
* <code>
|
||||
* // Returns: class="profile" id="picture"
|
||||
* echo HTML::attributes(array('class' => 'profile', 'id' => 'picture'));
|
||||
* </code>
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
*/
|
||||
|
@ -410,6 +405,20 @@ public function obfuscate($value)
|
|||
* Magic Method for handling dynamic static methods.
|
||||
*
|
||||
* This method primarily handles dynamic calls to create links to named routes.
|
||||
*
|
||||
* <code>
|
||||
* // Create a link to the "profile" named route
|
||||
* echo HTML::link_to_profile('Profile');
|
||||
*
|
||||
* // Create a link to a named route with URI wildcard parameters
|
||||
* echo HTML::link_to_posts('Posts', array($year, $month));
|
||||
*
|
||||
* // Create a HTTPS link to the "profile" named route
|
||||
* echo HTML::link_to_secure_profile('Profile');
|
||||
*
|
||||
* // Create a HTTPS link to a named route URI wildcard parameters
|
||||
* echo HTML::link_to_secure_posts('Posts', array($year, $month));
|
||||
* </code>
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
|
|
|
@ -2,6 +2,13 @@
|
|||
|
||||
class Input {
|
||||
|
||||
/**
|
||||
* The file manager instance.
|
||||
*
|
||||
* @var File
|
||||
*/
|
||||
protected $file;
|
||||
|
||||
/**
|
||||
* The applicable input for the request.
|
||||
*
|
||||
|
@ -16,13 +23,6 @@ class Input {
|
|||
*/
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* The file manager instance.
|
||||
*
|
||||
* @var File
|
||||
*/
|
||||
protected $file;
|
||||
|
||||
/**
|
||||
* The cookie engine instance.
|
||||
*
|
||||
|
@ -33,6 +33,7 @@ class Input {
|
|||
/**
|
||||
* Create a new Input manager instance.
|
||||
*
|
||||
* @param File $file
|
||||
* @param Cookie $cookies
|
||||
* @param array $input
|
||||
* @param array $files
|
||||
|
|
|
@ -41,15 +41,21 @@ public function __construct(Config $config, $paths)
|
|||
*
|
||||
* // Begin retrieving a language line with replacements
|
||||
* $lang = Lang::line('validation.required', array('attribute' => 'email'));
|
||||
*
|
||||
* // Begin retrieving a language line in a given language
|
||||
* $lang = Lang::line('messages.welcome', null, 'sp');
|
||||
* </code>
|
||||
*
|
||||
* @param string $key
|
||||
* @param array $replacements
|
||||
* @param string $language
|
||||
* @return Lang
|
||||
*/
|
||||
public function line($key, $replacements = array())
|
||||
public function line($key, $replacements = array(), $language = null)
|
||||
{
|
||||
return new Lang($key, $replacements, $this->config->get('application.language'), $this->paths);
|
||||
$language = ( ! is_null($language)) $this->config->get('application.language') : $language;
|
||||
|
||||
return new Lang($key, (array) $replacements, $language, $this->paths);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -81,6 +81,11 @@
|
|||
$session->close($container->resolve('laravel.session'), $config->get('session'));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Send the queued cookies to the browser.
|
||||
// --------------------------------------------------------------
|
||||
$container->resolve('laravel.cookie')->send();
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Send the response to the browser.
|
||||
// --------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue