mirror of
https://github.com/dannyvankooten/AltoRouter.git
synced 2025-08-03 15:07:43 +02:00
bump php version requirement to 7.0 and add types on all methods
This commit is contained in:
@@ -49,7 +49,7 @@ class AltoRouter
|
|||||||
* @param array $matchTypes
|
* @param array $matchTypes
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function __construct(array $routes = [], $basePath = '', array $matchTypes = [])
|
public function __construct(array $routes = [], string $basePath = '', array $matchTypes = [])
|
||||||
{
|
{
|
||||||
$this->addRoutes($routes);
|
$this->addRoutes($routes);
|
||||||
$this->setBasePath($basePath);
|
$this->setBasePath($basePath);
|
||||||
@@ -61,7 +61,7 @@ class AltoRouter
|
|||||||
* Useful if you want to process or display routes.
|
* Useful if you want to process or display routes.
|
||||||
* @return array All routes.
|
* @return array All routes.
|
||||||
*/
|
*/
|
||||||
public function getRoutes()
|
public function getRoutes(): array
|
||||||
{
|
{
|
||||||
return $this->routes;
|
return $this->routes;
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ class AltoRouter
|
|||||||
* Useful if you are running your application from a subdirectory.
|
* Useful if you are running your application from a subdirectory.
|
||||||
* @param string $basePath
|
* @param string $basePath
|
||||||
*/
|
*/
|
||||||
public function setBasePath($basePath)
|
public function setBasePath(string $basePath)
|
||||||
{
|
{
|
||||||
$this->basePath = $basePath;
|
$this->basePath = $basePath;
|
||||||
}
|
}
|
||||||
@@ -117,7 +117,7 @@ class AltoRouter
|
|||||||
* @param string $name Optional name of this route. Supply if you want to reverse route this url in your application.
|
* @param string $name Optional name of this route. Supply if you want to reverse route this url in your application.
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function map($method, $route, $target, $name = null)
|
public function map(string $method, string $route, $target, string $name = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->routes[] = [$method, $route, $target, $name];
|
$this->routes[] = [$method, $route, $target, $name];
|
||||||
@@ -128,8 +128,6 @@ class AltoRouter
|
|||||||
}
|
}
|
||||||
$this->namedRoutes[$name] = $route;
|
$this->namedRoutes[$name] = $route;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,11 +136,11 @@ class AltoRouter
|
|||||||
* Generate the URL for a named route. Replace regexes with supplied parameters
|
* Generate the URL for a named route. Replace regexes with supplied parameters
|
||||||
*
|
*
|
||||||
* @param string $routeName The name of the route.
|
* @param string $routeName The name of the route.
|
||||||
* @param array @params Associative array of parameters to replace placeholders with.
|
* @param array $params Associative array of parameters to replace placeholders with.
|
||||||
* @return string The URL of the route with named parameters in place.
|
* @return string The URL of the route with named parameters in place.
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function generate($routeName, array $params = [])
|
public function generate(string $routeName, array $params = []): string
|
||||||
{
|
{
|
||||||
|
|
||||||
// Check if named route exists
|
// Check if named route exists
|
||||||
@@ -186,7 +184,7 @@ class AltoRouter
|
|||||||
* @param string $requestMethod
|
* @param string $requestMethod
|
||||||
* @return array|boolean Array with route information on success, false on failure (no match).
|
* @return array|boolean Array with route information on success, false on failure (no match).
|
||||||
*/
|
*/
|
||||||
public function match($requestUrl = null, $requestMethod = null)
|
public function match(string $requestUrl = null, string $requestMethod = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
$params = [];
|
$params = [];
|
||||||
@@ -264,10 +262,10 @@ class AltoRouter
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Compile the regex for a given route (EXPENSIVE)
|
* Compile the regex for a given route (EXPENSIVE)
|
||||||
* @param $route
|
* @param string $route
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function compileRoute($route)
|
protected function compileRoute(string $route): string
|
||||||
{
|
{
|
||||||
if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {
|
if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {
|
||||||
$matchTypes = $this->matchTypes;
|
$matchTypes = $this->matchTypes;
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.6.0"
|
"php": ">=7.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "9.6.*",
|
"phpunit/phpunit": "9.6.*",
|
||||||
|
Reference in New Issue
Block a user