diff --git a/src/Libs/Request.php b/src/Libs/Request.php new file mode 100644 index 0000000..885dc2d --- /dev/null +++ b/src/Libs/Request.php @@ -0,0 +1,57 @@ +path = $path; + $this->get = new Neuron($_GET); + $this->post = new Neuron($_POST); + + $contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : ''; + if ($contentType === "application/json") + $this->json = new Neuron( + (object) json_decode(trim(file_get_contents("php://input")), false) + ); + else + $this->json = new Neuron(); + + $this->params = new Neuron(); + } +} diff --git a/src/Libs/Router.php b/src/Libs/Router.php index c4eb377..d5cf244 100644 --- a/src/Libs/Router.php +++ b/src/Libs/Router.php @@ -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)) {