Refactoring URL class.
This commit is contained in:
parent
6e9bf0a0e3
commit
3c216d897f
|
@ -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
|
if ($https and strpos($base, 'http://') === 0)
|
||||||
// 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)
|
|
||||||
{
|
{
|
||||||
$base = 'https://'.substr($base, 7);
|
$base = 'https://'.substr($base, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rtrim($base, '/').'/'.trim($url, '/');
|
return $base.'/'.ltrim($url, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,9 +46,9 @@ public static function to_secure($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()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue