mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 02:02:19 +00:00
8c5d8c2dc9
- Fixed: namespace being prepended on `RouterController` routes with absolute namespaces. - Fixed: match domain on `RouteController` and `RouteResource`. - Fixed: strict url-matching on `RouteController`. Fix should provide better url-matching. - Fixed: `RouterResource` always matching first url when having simular urls (ex: `/funny-cat` and `/funny-dog`). - Added `loadRoutes` method to `Router` class so routes now can be loaded without routing the request (useful when running in Cli etc). - Removed `getInstance` from `Router` class. Please use `SimpleRouter::router()` for singleton usage instead. - Added `getRemoteAddr` alias-method for `getIp` in `Request` class. - Added `getValue` to `IInputItem` interface. - Other minor optimizations. - Updated documentation with note on absolute/relative namespaces.
36 lines
845 B
PHP
36 lines
845 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;
|
|
}
|
|
|
|
/* Make regular expression based on route */
|
|
$parameters = $this->parseParameters($this->url, $url);
|
|
if ($parameters === null) {
|
|
return false;
|
|
}
|
|
|
|
$this->setParameters($parameters);
|
|
|
|
return true;
|
|
}
|
|
|
|
} |