From f3be544b1a35a9b49d1f4075fa4ae2a26acec6f0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 4 Feb 2012 10:58:38 -0600 Subject: [PATCH] cache base url. --- laravel/asset.php | 1 - laravel/url.php | 23 ++++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/laravel/asset.php b/laravel/asset.php index dea24519..8b6f9308 100644 --- a/laravel/asset.php +++ b/laravel/asset.php @@ -78,7 +78,6 @@ class Asset_Container { * Create a new asset container instance. * * @param string $name - * @param HTML $html * @return void */ public function __construct($name) diff --git a/laravel/url.php b/laravel/url.php index 30f83216..11b142dc 100644 --- a/laravel/url.php +++ b/laravel/url.php @@ -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 @@ public static function base() // 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; } /**