Improve params.

This commit is contained in:
kj 2020-03-16 22:54:12 -04:00
parent 255ef0a75d
commit b07333f3c8
2 changed files with 10 additions and 3 deletions

View File

@ -13,6 +13,10 @@ class Params {
} }
} }
public function __isset($index) {
return isset($this->data[$index]);
}
public function __get($index){ public function __get($index){
return (isset($this->data[$index]) && $this->data[$index] != '') ? $this->data[$index] : null; return (isset($this->data[$index]) && $this->data[$index] != '') ? $this->data[$index] : null;
} }

View File

@ -1,4 +1,5 @@
<?php <?php
namespace Libs; namespace Libs;
use Libs\Request; use Libs\Request;
@ -119,16 +120,18 @@ class Router{
if (isset($router['middleware'])){ if (isset($router['middleware'])){
$middleware = explode('::',$router['middleware']); $middleware = explode('::',$router['middleware']);
$data = call_user_func_array($middleware, [$router['callback'], $args, $params]); $data = call_user_func_array($middleware, [$router['callback'], $args, $params]);
}else } else {
$params[] = $args; $params[] = $args;
$data = call_user_func_array($router['callback'], $params); $data = call_user_func_array($router['callback'], $params);
}
}else{ }else{
if (isset($router['middleware'])){ if (isset($router['middleware'])){
$middleware = explode('::',$router['middleware']); $middleware = explode('::',$router['middleware']);
$data = call_user_func_array($middleware, [$router['callback'], $args]); $data = call_user_func_array($middleware, [$router['callback'], $args]);
}else } else {
$data = call_user_func_array($router['callback'], [$args]); $data = call_user_func_array($router['callback'], [$args]);
} }
}
if (isset($data)){ if (isset($data)){
header('Content-Type: application/json'); header('Content-Type: application/json');