Commit 2f999397 by Taylor Otwell

Trim comment bloat from URL class.

parent a2406c01
...@@ -12,9 +12,6 @@ class URL { ...@@ -12,9 +12,6 @@ class URL {
*/ */
public static function to($url = '', $https = false, $asset = false) public static function to($url = '', $https = false, $asset = false)
{ {
// ----------------------------------------------------
// Return the URL unchanged if it is already formed.
// ----------------------------------------------------
if (strpos($url, '://') !== false) if (strpos($url, '://') !== false)
{ {
return $url; return $url;
...@@ -22,19 +19,13 @@ class URL { ...@@ -22,19 +19,13 @@ class URL {
$base = Config::get('application.url'); $base = Config::get('application.url');
// ---------------------------------------------------- // Assets live in the public directory, so we only want to append
// Assets live in the public directory, so we don't // the index file if the URL is to an asset.
// want to append the index file to the URL if the
// URL is to an asset.
// ----------------------------------------------------
if ( ! $asset) if ( ! $asset)
{ {
$base .= '/'.Config::get('application.index'); $base .= '/'.Config::get('application.index');
} }
// ----------------------------------------------------
// Does the URL need an HTTPS protocol?
// ----------------------------------------------------
if (strpos($base, 'http://') === 0 and $https) if (strpos($base, 'http://') === 0 and $https)
{ {
$base = 'https://'.substr($base, 7); $base = 'https://'.substr($base, 7);
...@@ -78,18 +69,13 @@ class URL { ...@@ -78,18 +69,13 @@ class URL {
{ {
if ( ! is_null($route = Route\Finder::find($name))) if ( ! is_null($route = Route\Finder::find($name)))
{ {
// ----------------------------------------------------
// Get the first URI assigned to the route. // Get the first URI assigned to the route.
// ----------------------------------------------------
$uris = explode(', ', key($route)); $uris = explode(', ', key($route));
$uri = substr($uris[0], strpos($uris[0], '/')); $uri = substr($uris[0], strpos($uris[0], '/'));
// ---------------------------------------------------- // Replace any parameters in the URI. This allows the dynamic creation of URLs
// Replace any parameters in the URI. This allows // that contain parameter wildcards.
// the dynamic creation of URLs that contain parameter
// wildcards.
// ----------------------------------------------------
foreach ($parameters as $parameter) foreach ($parameters as $parameter)
{ {
$uri = preg_replace('/\(.+?\)/', $parameter, $uri, 1); $uri = preg_replace('/\(.+?\)/', $parameter, $uri, 1);
...@@ -122,16 +108,10 @@ class URL { ...@@ -122,16 +108,10 @@ class URL {
*/ */
public static function slug($title, $separator = '-') public static function slug($title, $separator = '-')
{ {
// ---------------------------------------------------- // Remove all characters that are not the separator, letters, numbers, or whitespace.
// Remove all characters that are not the separator,
// letters, numbers, or whitespace.
// ----------------------------------------------------
$title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', Str::lower($title)); $title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', Str::lower($title));
// ---------------------------------------------------- // Replace all separator characters and whitespace by a single separator
// Replace all separator characters and whitespace by
// a single separator
// ----------------------------------------------------
$title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title); $title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title);
return trim($title, $separator); return trim($title, $separator);
...@@ -144,17 +124,13 @@ class URL { ...@@ -144,17 +124,13 @@ class URL {
{ {
$parameters = (isset($parameters[0])) ? $parameters[0] : array(); $parameters = (isset($parameters[0])) ? $parameters[0] : array();
// ----------------------------------------------------
// Dynamically create a secure route URL. // Dynamically create a secure route URL.
// ----------------------------------------------------
if (strpos($method, 'to_secure_') === 0) if (strpos($method, 'to_secure_') === 0)
{ {
return static::to_route(substr($method, 10), $parameters, true); return static::to_route(substr($method, 10), $parameters, true);
} }
// ----------------------------------------------------
// Dynamically create a route URL. // Dynamically create a route URL.
// ----------------------------------------------------
if (strpos($method, 'to_') === 0) if (strpos($method, 'to_') === 0)
{ {
return static::to_route(substr($method, 3), $parameters); return static::to_route(substr($method, 3), $parameters);
......
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