Commit 3c216d89 authored by Taylor Otwell's avatar Taylor Otwell

Refactoring URL class.

parent 6e9bf0a0
...@@ -5,33 +5,27 @@ class URL { ...@@ -5,33 +5,27 @@ class URL {
/** /**
* Generate an application URL. * Generate an application URL.
* *
* If the given URL is already well-formed, it will be returned unchanged.
*
* @param string $url * @param string $url
* @param bool $https * @param bool $https
* @param bool $asset
* @return string * @return string
*/ */
public static function to($url = '', $https = false, $asset = false) public static function to($url = '', $https = false)
{ {
if (strpos($url, '://') !== false) if (filter_var($url, FILTER_VALIDATE_URL) !== false)
{ {
return $url; return $url;
} }
$base = Config::get('application.url'); $base = Config::get('application.url').'/'.Config::get('application.index');
// If the URL is being generated for a public asset such as an
// image, we do not want to include "index.php" in the path.
if ( ! $asset)
{
$base .= '/'.Config::get('application.index');
}
if (strpos($base, 'http://') === 0 and $https) if ($https and strpos($base, 'http://') === 0)
{ {
$base = 'https://'.substr($base, 7); $base = 'https://'.substr($base, 7);
} }
return rtrim($base, '/').'/'.trim($url, '/'); return $base.'/'.ltrim($url, '/');
} }
/** /**
...@@ -52,9 +46,9 @@ class URL { ...@@ -52,9 +46,9 @@ class URL {
* @param string $url * @param string $url
* @return string * @return string
*/ */
public static function to_asset($url = '') public static function to_asset($url)
{ {
return static::to($url, Request::is_secure(), true); return str_replace('/'.Config::get('application.index'), '', static::to($url, Request::is_secure()));
} }
/** /**
......
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