From 160e839e812bc165fd4d09f61409cc1935f40236 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 23 Feb 2012 16:18:08 -0600 Subject: [PATCH] cleaning up classes. --- laravel/cookie.php | 2 +- laravel/url.php | 38 +++++++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/laravel/cookie.php b/laravel/cookie.php index c3660642..790b7d97 100644 --- a/laravel/cookie.php +++ b/laravel/cookie.php @@ -33,7 +33,7 @@ public static function send() // All cookies are stored in the "jar" when set and not sent directly to the // browser. This simply makes testing all of the cookie stuff very easy - // since the jar can be inspected by the tests. + // since the jar can be inspected by the application's tests. foreach (static::$jar as $cookie) { static::set($cookie); diff --git a/laravel/url.php b/laravel/url.php index 9d07eb0b..ae235db2 100644 --- a/laravel/url.php +++ b/laravel/url.php @@ -70,24 +70,36 @@ public static function base() } elseif (isset($_SERVER['HTTP_HOST'])) { - $protocol = (Request::secure()) ? 'https://' : 'http://'; - - // Basically, by removing the basename, we are removing everything after the - // and including the front controller from the request URI. Leaving us with - // the path in which the framework is installed. - $script = $_SERVER['SCRIPT_NAME']; - - $path = str_replace(basename($script), '', $script); - - // Now that we have the base URL, all we need to do is attach the protocol - // and the HTTP_HOST to build the full URL for the application. We also - // trim off trailing slashes to clean the URL. - $base = rtrim($protocol.$_SERVER['HTTP_HOST'].$path, '/'); + $base = static::guess(); } return static::$base = $base; } + /** + * Guess the application URL based on the $_SERVER variables. + * + * @return string + */ + protected static function guess() + { + $protocol = (Request::secure()) ? 'https://' : 'http://'; + + // Basically, by removing the basename, we are removing everything after + // the and including the front controller from the URI. Leaving us with + // the installation path for the application. + $script = $_SERVER['SCRIPT_NAME']; + + $path = str_replace(basename($script), '', $script); + + // Now that we have the URL, all we need to do is attach the protocol + // protocol and HTTP_HOST to build the URL for the application, and + // we also trim off trailing slashes for cleanliness. + $uri = $protocol.$_SERVER['HTTP_HOST'].$path; + + return rtrim($uri, '/'); + } + /** * Generate an application URL. *