1
0
mirror of https://github.com/dannyvankooten/AltoRouter.git synced 2025-01-17 12:18:16 +01:00

bump php version requirement to 7.0 and add types on all methods

This commit is contained in:
Danny van Kooten 2023-10-09 20:54:04 +02:00
parent 77a2e14681
commit 4270bb5ca2
2 changed files with 10 additions and 12 deletions

View File

@ -49,7 +49,7 @@ class AltoRouter
* @param array $matchTypes
* @throws Exception
*/
public function __construct(array $routes = [], $basePath = '', array $matchTypes = [])
public function __construct(array $routes = [], string $basePath = '', array $matchTypes = [])
{
$this->addRoutes($routes);
$this->setBasePath($basePath);
@ -61,7 +61,7 @@ class AltoRouter
* Useful if you want to process or display routes.
* @return array All routes.
*/
public function getRoutes()
public function getRoutes(): array
{
return $this->routes;
}
@ -93,7 +93,7 @@ class AltoRouter
* Useful if you are running your application from a subdirectory.
* @param string $basePath
*/
public function setBasePath($basePath)
public function setBasePath(string $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.
* @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];
@ -128,8 +128,6 @@ class AltoRouter
}
$this->namedRoutes[$name] = $route;
}
return;
}
/**
@ -138,11 +136,11 @@ class AltoRouter
* Generate the URL for a named route. Replace regexes with supplied parameters
*
* @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.
* @throws Exception
*/
public function generate($routeName, array $params = [])
public function generate(string $routeName, array $params = []): string
{
// Check if named route exists
@ -186,7 +184,7 @@ class AltoRouter
* @param string $requestMethod
* @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 = [];
@ -264,10 +262,10 @@ class AltoRouter
/**
* Compile the regex for a given route (EXPENSIVE)
* @param $route
* @param string $route
* @return string
*/
protected function compileRoute($route)
protected function compileRoute(string $route): string
{
if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {
$matchTypes = $this->matchTypes;

View File

@ -20,7 +20,7 @@
}
],
"require": {
"php": ">=5.6.0"
"php": ">=7.0"
},
"require-dev": {
"phpunit/phpunit": "9.6.*",