Commit 160e839e authored by Taylor Otwell's avatar Taylor Otwell

cleaning up classes.

parent fadadd0f
...@@ -33,7 +33,7 @@ class Cookie { ...@@ -33,7 +33,7 @@ class Cookie {
// All cookies are stored in the "jar" when set and not sent directly to the // 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 // 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) foreach (static::$jar as $cookie)
{ {
static::set($cookie); static::set($cookie);
......
...@@ -70,22 +70,34 @@ class URL { ...@@ -70,22 +70,34 @@ class URL {
} }
elseif (isset($_SERVER['HTTP_HOST'])) elseif (isset($_SERVER['HTTP_HOST']))
{ {
$protocol = (Request::secure()) ? 'https://' : 'http://'; $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 // Basically, by removing the basename, we are removing everything after
// and including the front controller from the request URI. Leaving us with // the and including the front controller from the URI. Leaving us with
// the path in which the framework is installed. // the installation path for the application.
$script = $_SERVER['SCRIPT_NAME']; $script = $_SERVER['SCRIPT_NAME'];
$path = str_replace(basename($script), '', $script); $path = str_replace(basename($script), '', $script);
// Now that we have the base URL, all we need to do is attach the protocol // Now that we have the URL, all we need to do is attach the protocol
// and the HTTP_HOST to build the full URL for the application. We also // protocol and HTTP_HOST to build the URL for the application, and
// trim off trailing slashes to clean the URL. // we also trim off trailing slashes for cleanliness.
$base = rtrim($protocol.$_SERVER['HTTP_HOST'].$path, '/'); $uri = $protocol.$_SERVER['HTTP_HOST'].$path;
}
return static::$base = $base; return rtrim($uri, '/');
} }
/** /**
......
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