refactoring various classes.
This commit is contained in:
@@ -13,11 +13,14 @@ class IoC {
|
|||||||
* Get the active container instance.
|
* Get the active container instance.
|
||||||
*
|
*
|
||||||
* The container is set early in the request cycle and can be access here for
|
* 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>
|
* <code>
|
||||||
|
* // Get the active container instance
|
||||||
|
* $container = IoC::container();
|
||||||
|
*
|
||||||
* // Get the active container instance and call the resolve method
|
* // Get the active container instance and call the resolve method
|
||||||
* $instance = IoC::container()->resolve('instance');
|
* $container = IoC::container()->resolve('instance');
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @return Container
|
* @return Container
|
||||||
@@ -73,15 +76,15 @@ class Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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>
|
* <code>
|
||||||
* // Register a dependency in the container
|
* // Register an object in the container
|
||||||
* IoC::register('something', function($container) {return new Something;});
|
* 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);
|
* IoC::register('something', function($container) {return new Something;}, true);
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
@@ -95,7 +98,7 @@ class Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if a dependency has been registered in the container.
|
* Determine if an object has been registered in the container.
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return bool
|
* @return bool
|
||||||
@@ -106,13 +109,13 @@ class Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
* Singletons will only be instantiated the first time they are resolved. On subsequent
|
||||||
* requests for the object, the original instance will be returned.
|
* requests for the object, the original instance will be returned.
|
||||||
*
|
*
|
||||||
* <code>
|
* <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;});
|
* IoC::singleton('something', function($container) {return new Something;});
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
@@ -129,13 +132,11 @@ class Container {
|
|||||||
* Register an instance as a singleton.
|
* Register an instance as a singleton.
|
||||||
*
|
*
|
||||||
* This method allows you to register an already existing object instance with the
|
* 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>
|
* <code>
|
||||||
* // Register an instance with the IoC container
|
* // Register an instance with the IoC container
|
||||||
* $something = new Something;
|
* IoC::instance('something', new Something);
|
||||||
*
|
|
||||||
* IoC::instance('something', $something);
|
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
@@ -148,12 +149,14 @@ class Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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>
|
* <code>
|
||||||
* // Get the "something" dependency out of the IoC container
|
* // Get the "something" object out of the IoC container
|
||||||
* $something = IoC::resolve('something');
|
* $something = IoC::resolve('something');
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -9,6 +9,13 @@ class Cookie {
|
|||||||
*/
|
*/
|
||||||
protected $cookies;
|
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.
|
* Create a new cookie manager instance.
|
||||||
*
|
*
|
||||||
@@ -38,7 +45,7 @@ class Cookie {
|
|||||||
* // Get the value of a cookie
|
* // Get the value of a cookie
|
||||||
* $value = Cookie::get('color');
|
* $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');
|
* $value = Cookie::get('color', 'blue');
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
@@ -99,7 +106,22 @@ class Cookie {
|
|||||||
|
|
||||||
$time = ($minutes != 0) ? time() + ($minutes * 60) : 0;
|
$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,14 +346,9 @@ class HTML {
|
|||||||
/**
|
/**
|
||||||
* Build a list of HTML attributes from an 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
|
* @param array $attributes
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function attributes($attributes)
|
public function attributes($attributes)
|
||||||
{
|
{
|
||||||
$html = array();
|
$html = array();
|
||||||
@@ -410,6 +405,20 @@ class HTML {
|
|||||||
* Magic Method for handling dynamic static methods.
|
* Magic Method for handling dynamic static methods.
|
||||||
*
|
*
|
||||||
* This method primarily handles dynamic calls to create links to named routes.
|
* 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)
|
public function __call($method, $parameters)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
class Input {
|
class Input {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The file manager instance.
|
||||||
|
*
|
||||||
|
* @var File
|
||||||
|
*/
|
||||||
|
protected $file;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The applicable input for the request.
|
* The applicable input for the request.
|
||||||
*
|
*
|
||||||
@@ -16,13 +23,6 @@ class Input {
|
|||||||
*/
|
*/
|
||||||
protected $files;
|
protected $files;
|
||||||
|
|
||||||
/**
|
|
||||||
* The file manager instance.
|
|
||||||
*
|
|
||||||
* @var File
|
|
||||||
*/
|
|
||||||
protected $file;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The cookie engine instance.
|
* The cookie engine instance.
|
||||||
*
|
*
|
||||||
@@ -33,6 +33,7 @@ class Input {
|
|||||||
/**
|
/**
|
||||||
* Create a new Input manager instance.
|
* Create a new Input manager instance.
|
||||||
*
|
*
|
||||||
|
* @param File $file
|
||||||
* @param Cookie $cookies
|
* @param Cookie $cookies
|
||||||
* @param array $input
|
* @param array $input
|
||||||
* @param array $files
|
* @param array $files
|
||||||
|
|||||||
@@ -41,15 +41,21 @@ class Lang_Factory {
|
|||||||
*
|
*
|
||||||
* // Begin retrieving a language line with replacements
|
* // Begin retrieving a language line with replacements
|
||||||
* $lang = Lang::line('validation.required', array('attribute' => 'email'));
|
* $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>
|
* </code>
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @param array $replacements
|
* @param array $replacements
|
||||||
|
* @param string $language
|
||||||
* @return Lang
|
* @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 @@ if (isset($session))
|
|||||||
$session->close($container->resolve('laravel.session'), $config->get('session'));
|
$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.
|
// Send the response to the browser.
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user