cache base url.

This commit is contained in:
Taylor Otwell
2012-02-04 10:58:38 -06:00
parent d7fcd74a02
commit f3be544b1a
2 changed files with 20 additions and 4 deletions

View File

@@ -2,6 +2,13 @@
class URL {
/**
* The cached base URL.
*
* @var string
*/
public static $base;
/**
* Get the base URL of the application.
*
@@ -9,7 +16,17 @@ class URL {
*/
public static function base()
{
if (($base = Config::get('application.url')) !== '') return $base;
if (isset(static::$base)) return static::$base;
$base = 'http://localhost';
// If the application URL configuration is set, we will just use
// that instead of trying to guess the URL based on the $_SERVER
// array's host and script name.
if (($url = Config::get('application.url')) !== '')
{
$base = $url;
}
if (isset($_SERVER['HTTP_HOST']))
{
@@ -21,10 +38,10 @@ class URL {
// construct the base URL to the application.
$path = str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
return rtrim($protocol.$_SERVER['HTTP_HOST'].$path, '/');
$base = rtrim($protocol.$_SERVER['HTTP_HOST'].$path, '/');
}
return 'http://localhost';
return static::$base = $base;
}
/**