Add Lib\Request.
This commit is contained in:
@ -133,36 +133,6 @@ class Router {
|
||||
return new static();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Neuron
|
||||
* Devuelve un objeto que contiene los atributos:
|
||||
* post - Donde se encuentran los valores enviados por $_POST.
|
||||
* get - Donde se encuentran los valores enviados por $_GET.
|
||||
* json - Donde se encuentran los valores JSON enviados en el body.
|
||||
*
|
||||
*/
|
||||
private static function getReq(): Neuron {
|
||||
$req = new Neuron();
|
||||
$req->get = new Neuron($_GET);
|
||||
$req->post = new Neuron($_POST);
|
||||
$req->json = new Neuron(static::get_json());
|
||||
$req->params = new Neuron();
|
||||
$req->path = static::currentPath();
|
||||
return $req;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return object
|
||||
* Devuelve un objeto con los datos recibidos en JSON.
|
||||
*/
|
||||
private static function get_json(): object {
|
||||
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
|
||||
if ($contentType === "application/json") {
|
||||
return (object) json_decode(trim(file_get_contents("php://input")));
|
||||
}
|
||||
return (object) '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconfigura el callback final de la última ruta.
|
||||
*
|
||||
@ -297,7 +267,7 @@ class Router {
|
||||
}
|
||||
|
||||
/**
|
||||
* Devuelve la ruta actual.
|
||||
* Devuelve la ruta actual tomando como raíz la ruta de instalación de DuckBrain.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@ -336,7 +306,7 @@ class Router {
|
||||
default => static::$get
|
||||
};
|
||||
|
||||
$req = static::getReq();
|
||||
$req = new Request(static::currentPath());
|
||||
|
||||
foreach ($routers as $router) { // revisa todos los routers para ver si coinciden con la ruta actual
|
||||
if (preg_match_all('/^'.$router['path'].'\/?$/si',$path, $matches, PREG_PATTERN_ORDER)) {
|
||||
|
Reference in New Issue
Block a user