diff --git a/laravel/container.php b/laravel/container.php index ff0f4eac..77d48819 100644 --- a/laravel/container.php +++ b/laravel/container.php @@ -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. * * + * // 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'); * * * @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. * * - * // 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); * * @@ -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. * * - * // 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;}); * * @@ -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. * * * // Register an instance with the IoC container - * $something = new Something; - * - * IoC::instance('something', $something); + * IoC::instance('something', new Something); * * * @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. * * - * // Get the "something" dependency out of the IoC container + * // Get the "something" object out of the IoC container * $something = IoC::resolve('something'); * * diff --git a/laravel/cookie.php b/laravel/cookie.php index 8765113e..c78ea0ca 100644 --- a/laravel/cookie.php +++ b/laravel/cookie.php @@ -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'); * * @@ -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); + } } /** diff --git a/laravel/html.php b/laravel/html.php index 6859a469..6b521c67 100644 --- a/laravel/html.php +++ b/laravel/html.php @@ -346,14 +346,9 @@ private function list_elements($type, $list, $attributes = array()) /** * Build a list of HTML attributes from an array. * - * - * // Returns: class="profile" id="picture" - * echo HTML::attributes(array('class' => 'profile', 'id' => 'picture')); - * - * * @param array $attributes * @return string - */ + */ public function attributes($attributes) { $html = array(); @@ -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. + * + * + * // 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)); + * */ public function __call($method, $parameters) { diff --git a/laravel/input.php b/laravel/input.php index 62183777..26d50cdf 100644 --- a/laravel/input.php +++ b/laravel/input.php @@ -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 diff --git a/laravel/lang.php b/laravel/lang.php index 38897605..7fdc3c6a 100644 --- a/laravel/lang.php +++ b/laravel/lang.php @@ -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'); * * * @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); } } diff --git a/laravel/laravel.php b/laravel/laravel.php index ba54492a..ba754276 100644 --- a/laravel/laravel.php +++ b/laravel/laravel.php @@ -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. // --------------------------------------------------------------