Add Lib\Request.
This commit is contained in:
57
src/Libs/Request.php
Normal file
57
src/Libs/Request.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Request - DuckBrain
|
||||
*
|
||||
* Libería complementaria de la libería Router.
|
||||
* Contiene el cuerpo básico de la petición http (POST, GET, JSON, etc).
|
||||
*
|
||||
* @author KJ
|
||||
* @website https://kj2.me
|
||||
* @licence MIT
|
||||
*/
|
||||
|
||||
namespace Libs;
|
||||
|
||||
class Request extends Neuron {
|
||||
/**
|
||||
* @var Neuron $get Objeto con todos los valores de $_GET.
|
||||
*/
|
||||
public Neuron $get;
|
||||
/**
|
||||
* @var Neuron $post Objeto con todos los valores de $_POST.
|
||||
*/
|
||||
public Neuron $post;
|
||||
/**
|
||||
* @var Neuron $json Objeto con todos los valores json enviados.
|
||||
*/
|
||||
public Neuron $json;
|
||||
/**
|
||||
* @var mixed $params Objeto con todos los valores pseudovariables de la uri.
|
||||
*/
|
||||
public Neuron $params;
|
||||
/**
|
||||
* @var mixed $path Ruta actual tomando como raíz la instalación de DuckBrain.
|
||||
*/
|
||||
public string $path;
|
||||
|
||||
/**
|
||||
* __construct
|
||||
*
|
||||
* @param string $path Ruta actual tomando como raíz la instalación de DuckBrain.
|
||||
*/
|
||||
public function __construct(string $path = '/') {
|
||||
$this->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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user