Browse Source

Refactoring URL class.

Taylor Otwell 13 years ago
parent
commit
3c216d897f
1 changed files with 9 additions and 15 deletions
  1. 9 15
      system/url.php

+ 9 - 15
system/url.php

@@ -5,33 +5,27 @@ class URL {
 	/**
 	 * Generate an application URL.
 	 *
+	 * If the given URL is already well-formed, it will be returned unchanged.
+	 *
 	 * @param  string  $url
 	 * @param  bool    $https
-	 * @param  bool    $asset
 	 * @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;
 		}
 
-		$base = Config::get('application.url');
-
-		// 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');
-		}
+		$base = Config::get('application.url').'/'.Config::get('application.index');
 
-		if (strpos($base, 'http://') === 0 and $https)
+		if ($https and strpos($base, 'http://') === 0)
 		{
 			$base = 'https://'.substr($base, 7);
 		}
 
-		return rtrim($base, '/').'/'.trim($url, '/');
+		return $base.'/'.ltrim($url, '/');
 	}
 
 	/**
@@ -52,9 +46,9 @@ class URL {
 	 * @param  string  $url
 	 * @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()));
 	}
 
 	/**