Change switch to match.

This commit is contained in:
KJ 2023-10-20 16:26:17 -04:00
parent e2094ccb4a
commit cd01ab9e72
1 changed files with 7 additions and 18 deletions

View File

@ -328,24 +328,13 @@ class Router {
*/
public static function apply(): void {
$path = static::currentPath();
$routers = [];
switch ($_SERVER['REQUEST_METHOD']){ // Según el método selecciona un arreglo de routers configurados
case 'POST':
$routers = static::$post;
break;
case 'PUT':
$routers = static::$put;
break;
case 'PATCH':
$routers = static::$patch;
break;
case 'DELETE':
$routers = static::$delete;
break;
default:
$routers = static::$get;
break;
}
$routers = match($_SERVER['REQUEST_METHOD']) { // Según el método selecciona un arreglo de routers configurados
'POST' => static::$post,
'PUT' => static::$put,
'PATCH' => static::$patch,
'DELETE' => static::$delete,
default => static::$get
};
$req = static::getReq();