mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-10 22:42:14 +00:00
9dd80dd1d9
- Fixed global regex match not working properly. - Feature: added option to change regular expression used for parameters on routes. - Added unit-tests for custom parameter regular expression. - Updated documentation to reflect new features.
41 lines
1002 B
PHP
41 lines
1002 B
PHP
<?php
|
|
|
|
namespace Pecee\SimpleRouter\Route;
|
|
|
|
use Pecee\Http\Request;
|
|
|
|
class RouteUrl extends LoadableRoute
|
|
{
|
|
public function __construct($url, $callback)
|
|
{
|
|
$this->setUrl($url);
|
|
$this->setCallback($callback);
|
|
}
|
|
|
|
public function matchRoute($url, Request $request)
|
|
{
|
|
$url = parse_url(urldecode($url), PHP_URL_PATH);
|
|
$url = rtrim($url, '/') . '/';
|
|
|
|
/* Match global regular-expression for route */
|
|
$regexMatch = $this->matchRegex($request, $url);
|
|
|
|
if ($regexMatch === false) {
|
|
return false;
|
|
}
|
|
|
|
/* Parse parameters from current route */
|
|
$parameters = $this->parseParameters($this->url, $url);
|
|
|
|
/* If no custom regular expression or parameters was found on this route, we stop */
|
|
if ($regexMatch === null && $parameters === null) {
|
|
return false;
|
|
}
|
|
|
|
/* Set the parameters */
|
|
$this->setParameters((array)$parameters);
|
|
|
|
return true;
|
|
}
|
|
|
|
} |