refactoring the router.
This commit is contained in:
parent
54e0bef6b5
commit
7aecd7857f
|
@ -219,6 +219,17 @@ function array_strip_slashes($array)
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Divide an array into two arrays. One with keys and the other with values.
|
||||||
|
*
|
||||||
|
* @param array $array
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function array_divide($array)
|
||||||
|
{
|
||||||
|
return array(array_keys($array), array_values($array));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if "Magic Quotes" are enabled on the server.
|
* Determine if "Magic Quotes" are enabled on the server.
|
||||||
*
|
*
|
||||||
|
|
|
@ -167,7 +167,9 @@ public static function route($method, $uri)
|
||||||
$uri = ltrim($uri, '/');
|
$uri = ltrim($uri, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
return static::controller($bundle, $method, $destination, Str::segments($uri));
|
$segments = Str::segments($uri);
|
||||||
|
|
||||||
|
return static::controller($bundle, $method, $destination, $segments);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -285,21 +287,26 @@ protected static function controller_key($segments, $directory)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translate route URI wildcards into actual regular expressions.
|
* Translate route URI wildcards into regular expressions.
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected static function wildcards($key)
|
protected static function wildcards($key)
|
||||||
{
|
{
|
||||||
|
list($search, $replace) = array_divide(static::$optional);
|
||||||
|
|
||||||
// For optional parameters, first translate the wildcards to their
|
// For optional parameters, first translate the wildcards to their
|
||||||
// regex equivalent, sans the ")?" ending. We'll add the endings
|
// regex equivalent, sans the ")?" ending. We'll add the endings
|
||||||
// back on after we know how many replacements we made.
|
// back on after we know how many replacements we made.
|
||||||
$key = str_replace(array_keys(static::$optional), array_values(static::$optional), $key, $count);
|
$key = str_replace($search, $replace, $key, $count);
|
||||||
|
|
||||||
$key .= ($count > 0) ? str_repeat(')?', $count) : '';
|
$key .= ($count > 0) ? str_repeat(')?', $count) : '';
|
||||||
|
|
||||||
return str_replace(array_keys(static::$patterns), array_values(static::$patterns), $key);
|
// For "regular" parameters, we can just do a simple translate
|
||||||
|
// using the patterns array. There is not need to cap the
|
||||||
|
// pattern like we did with optional parameters.
|
||||||
|
return strtr($key, static::$patterns);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue