Change switch to match.

This commit is contained in:
KJ 2023-10-20 16:26:17 -04:00
parent e2094ccb4a
commit cd01ab9e72

View File

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