mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 08:47:52 +00:00
Development
- Ensure that request-method is always lowercase. - Fixed spaces instead of tabs to comply with PSR-2.
This commit is contained in:
@@ -5,45 +5,45 @@ use Pecee\Http\Request;
|
||||
|
||||
class RouteUrl extends LoadableRoute
|
||||
{
|
||||
public function __construct($url, $callback)
|
||||
{
|
||||
$this->setUrl($url);
|
||||
$this->setCallback($callback);
|
||||
}
|
||||
public function __construct($url, $callback)
|
||||
{
|
||||
$this->setUrl($url);
|
||||
$this->setCallback($callback);
|
||||
}
|
||||
|
||||
public function matchRoute(Request $request)
|
||||
{
|
||||
$url = parse_url(urldecode($request->getUri()), PHP_URL_PATH);
|
||||
$url = rtrim($url, '/') . '/';
|
||||
public function matchRoute(Request $request)
|
||||
{
|
||||
$url = parse_url(urldecode($request->getUri()), PHP_URL_PATH);
|
||||
$url = rtrim($url, '/') . '/';
|
||||
|
||||
// Match on custom defined regular expression
|
||||
if ($this->regex !== null) {
|
||||
$parameters = [];
|
||||
if (preg_match($this->regex, $request->getHost() . $url, $parameters)) {
|
||||
/* Remove global match */
|
||||
if(count($parameters) > 1) {
|
||||
array_shift($parameters);
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
// Match on custom defined regular expression
|
||||
if ($this->regex !== null) {
|
||||
$parameters = [];
|
||||
if (preg_match($this->regex, $request->getHost() . $url, $parameters)) {
|
||||
/* Remove global match */
|
||||
if (count($parameters) > 1) {
|
||||
array_shift($parameters);
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Make regular expression based on route
|
||||
$route = rtrim($this->url, '/') . '/';
|
||||
// Make regular expression based on route
|
||||
$route = rtrim($this->url, '/') . '/';
|
||||
|
||||
$parameters = $this->parseParameters($route, $url);
|
||||
$parameters = $this->parseParameters($route, $url);
|
||||
|
||||
if ($parameters !== null) {
|
||||
$this->parameters = array_merge($this->parameters, $parameters);
|
||||
if ($parameters !== null) {
|
||||
$this->parameters = array_merge($this->parameters, $parameters);
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user