Commit f3be544b authored by Taylor Otwell's avatar Taylor Otwell

cache base url.

parent d7fcd74a
......@@ -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)
......
......@@ -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;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment