diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 0000000..3b1e273
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1 @@
+github: [Josantonius]
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index b5216cd..62f1828 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,12 +1,13 @@
-.git*/
vendor/
-docs/*.pyc
-docs/_build
-build/artifacts/
+coverage/
+.vscode/
+docs/cache/
composer.phar
composer.lock
composer-test.lock
phpcbf-fixed.diff
-.idea
-.DS_STORE
-.php_cs.cache
\ No newline at end of file
+.php_cs.cache
+php-request.code-workspace
+.repository.md
+.phpunit.result.cache
+coverage.xml
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b3d0104..586a1cd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# CHANGELOG
+## 2.0.1 - 2022-08-18
+
+The repository was archived.
+
## 2.0.0 - 2018-09-22
* The library was completely refactored without compatibility with previous versions and only compatible with PHP versions equal to or greater than 7.0.
@@ -59,7 +63,7 @@
* Unit tests supported by `PHPUnit` were added.
* The repository was synchronized with Travis CI to implement continuous integration.
-
+
* Added `Request/src/bootstrap.php` file
* Added `Request/tests/bootstrap.php` file.
@@ -159,4 +163,3 @@
* Added `Josantonius\Request\Tests\RequestTest::testIsPut()` method.
* Added `Josantonius\Request\Tests\RequestTest::testIsDelete()` method.
* Added `Josantonius\Request\Tests\RequestTest::testIsAjax()` method.
-
diff --git a/README-ES (copia).md b/README-ES (copia).md
deleted file mode 100644
index 5a49173..0000000
--- a/README-ES (copia).md
+++ /dev/null
@@ -1,341 +0,0 @@
-# PHP Request library
-
-[![Latest Stable Version](https://poser.pugx.org/josantonius/Request/v/stable)](https://packagist.org/packages/josantonius/Request) [![Latest Unstable Version](https://poser.pugx.org/josantonius/Request/v/unstable)](https://packagist.org/packages/josantonius/Request) [![License](https://poser.pugx.org/josantonius/Request/license)](LICENSE) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/aa5b98dbbc5846399bb994318dce3c88)](https://www.codacy.com/app/Josantonius/PHP-Request?utm_source=github.com&utm_medium=referral&utm_content=Josantonius/PHP-Request&utm_campaign=Badge_Grade) [![Total Downloads](https://poser.pugx.org/josantonius/Request/downloads)](https://packagist.org/packages/josantonius/Request) [![Travis](https://travis-ci.org/Josantonius/PHP-Request.svg)](https://travis-ci.org/Josantonius/PHP-Request) [![PSR2](https://img.shields.io/badge/PSR-2-1abc9c.svg)](http://www.php-fig.org/psr/psr-2/) [![PSR4](https://img.shields.io/badge/PSR-4-9b59b6.svg)](http://www.php-fig.org/psr/psr-4/) [![CodeCov](https://codecov.io/gh/Josantonius/PHP-Request/branch/master/graph/badge.svg)](https://codecov.io/gh/Josantonius/PHP-Request)
-
-[English version](README.md)
-
-Biblioteca PHP para manejo de peticiones.
-
----
-
-- [Requisitos](#requisitos)
-- [Instalación](#instalación)
-- [Métodos disponibles](#métodos-disponibles)
-- [Cómo empezar](#cómo-empezar)
-- [Uso](#uso)
-- [Tests](#tests)
-- [Tareas pendientes](#-tareas-pendientes)
-- [Contribuir](#contribuir)
-- [Repositorio](#repositorio)
-- [Licencia](#licencia)
-- [Copyright](#copyright)
-
----
-
-## Requisitos
-
-Esta clase es soportada por versiones de **PHP 5.6** o superiores y es compatible con versiones de **HHVM 3.0** o superiores.
-
-## Instalación
-
-La mejor forma de instalar esta extensión es a través de [Composer](http://getcomposer.org/download/).
-
-Para instalar **PHP Request library**, simplemente escribe:
-
- $ composer require Josantonius/Request
-
-El comando anterior sólo instalará los archivos necesarios, si prefieres **descargar todo el código fuente** puedes utilizar:
-
- $ composer require Josantonius/Request --prefer-source
-
-También puedes **clonar el repositorio** completo con Git:
-
- $ git clone https://github.com/Josantonius/PHP-Request.git
-
-O **instalarlo manualmente**:
-
-[Descargar Request.php](https://raw.githubusercontent.com/Josantonius/PHP-Request/master/src/Request.php):
-
- $ wget https://raw.githubusercontent.com/Josantonius/PHP-Request/master/src/Request.php
-
-## Métodos disponibles
-
-Métodos disponibles en esta biblioteca:
-
-### - Acceso seguro a parámetros GET:
-
-```php
-Request::get($key);
-```
-
-| Atributo | Descripción | Tipo | Requerido | Predeterminado
-| --- | --- | --- | --- | --- |
-| $key | Clave para parámetro. | string | Sí | |
-
-**# Return** (mixed|null) → valor/es o null
-
-### - Acceso seguro a parámetros POST:
-
-```php
-Request::post($key);
-```
-
-| Atributo | Descripción | Tipo | Requerido | Predeterminado
-| --- | --- | --- | --- | --- |
-| $key | Clave para parámetro. | string | Sí | |
-
-**# Return** (mixed|null) → valor/es o null
-
-### - Acceso seguro a parámetros FILES:
-
-```php
-Request::files($key);
-```
-
-| Atributo | Descripción | Tipo | Requerido | Predeterminado
-| --- | --- | --- | --- | --- |
-| $key | Clave para parámetro. | string | Sí | |
-
-**# Return** (mixed|null) → valor/es o null
-
-### - Acceso seguro a parámetros PUT:
-
-```php
-Request::put($key);
-```
-
-| Atributo | Descripción | Tipo | Requerido | Predeterminado
-| --- | --- | --- | --- | --- |
-| $key | Clave para parámetro. | string | Sí | |
-
-**# Return** (mixed|null) → valor/es o null
-
-### - Acceso seguro a parámetros DEL:
-
-```php
-Request::del($key);
-```
-
-| Atributo | Descripción | Tipo | Requerido | Predeterminado
-| --- | --- | --- | --- | --- |
-| $key | Clave para parámetro. | string | Sí | |
-
-**# Return** (mixed|null) → valor/es o null
-
-### - Comprobar si es una petición GET:
-
-```php
-Request::isGet();
-```
-
-**# Return** (boolean)
-
-### - Comprobar si es una petición POST:
-
-```php
-Request::isPost();
-```
-
-**# Return** (boolean)
-
-### - Comprobar si es una petición PUT:
-
-```php
-Request::isPut();
-```
-
-**# Return** (boolean)
-
-### - Comprobar si es una petición DELETE:
-
-```php
-Request::isDelete();
-```
-
-**# Return** (boolean)
-
-### - Comprobar si es una petición AJAX:
-
-```php
-Request::isAjax();
-```
-
-**# Return** (boolean)
-
-## Cómo empezar
-
-Para utilizar esta biblioteca con **Composer**:
-
-```php
-require __DIR__ . '/vendor/autoload.php';
-
-use Josantonius\Request\Request;
-```
-
-Si la instalaste **manualmente**, utiliza:
-
-```php
-require_once __DIR__ . '/Request.php';
-
-use Josantonius\Request\Request;
-```
-
-## Uso
-
-Ejemplo de uso para esta biblioteca:
-
-### - Obtener todos los valores GET:
-
-```php
-$_GET = ['test' => 'value', 'test-2' => 1];
-
-Request::get();
-```
-
-### - Acceder al parámetro GET indicando clave específica:
-
-```php
-$_GET = ['test' => 'value', 'test-2' => 1];
-
-Request::get('test');
-```
-
-### - Obtener todos los valores POST:
-
-```php
-$_POST = ['test' => 'value', 'test-2' => 1];
-
-Request::post();
-```
-
-### - Acceder al parámetro POST indicando clave específica:
-
-```php
-$_POST = ['test' => 'value', 'test-2' => 1];
-
-Request::post('test');
-```
-
-### - Obtener todos los valores FILES:
-
-```php
-$_FILES = ['test' => 'value', 'test-2' => 1];
-
-Request::files();
-```
-
-### - Acceder al parámetro FILES indicando clave específica:
-
-```php
-$_FILES = ['test' => 'value', 'test-2' => 1];
-
-Request::files('test');
-```
-
-### - Obtener todos los valores PUT:
-
-```php
-$_PUT = ['test' => 'value', 'test-2' => 1];
-
-Request::put();
-```
-
-### - Acceder al parámetro PUT indicando clave específica:
-
-```php
-$_PUT = ['test' => 'value', 'test-2' => 1];
-
-Request::put('test');
-```
-
-### - Comprobar si es una petición POST:
-
-```php
-$_SERVER['REQUEST_METHOD'] = 'POST';
-
-Request::isPost()
-```
-
-### - Comprobar si es una petición PUT:
-
-```php
-$_SERVER['REQUEST_METHOD'] = 'PUT';
-
-Request::isPut()
-```
-
-### - Comprobar si es una petición DELETE:
-
-```php
-$_SERVER['REQUEST_METHOD'] = 'DELETE';
-
-Request::isDelete()
-```
-
-### - Comprobar si es una petición AJAX:
-
-```php
-$_SERVER['HTTP_X_REQUESTED_WITH'] = 'xmlhttprequest';
-
-Request::isAjax()
-```
-
-## Tests
-
-Para ejecutar las [pruebas](tests) necesitarás [Composer](http://getcomposer.org/download/) y seguir los siguientes pasos:
-
- $ git clone https://github.com/Josantonius/PHP-Request.git
-
- $ cd PHP-Request
-
- $ composer install
-
-Ejecutar pruebas unitarias con [PHPUnit](https://phpunit.de/):
-
- $ composer phpunit
-
-Ejecutar pruebas de estándares de código [PSR2](http://www.php-fig.org/psr/psr-2/) con [PHPCS](https://github.com/squizlabs/PHP_CodeSniffer):
-
- $ composer phpcs
-
-Ejecutar pruebas con [PHP Mess Detector](https://phpmd.org/) para detectar inconsistencias en el estilo de codificación:
-
- $ composer phpmd
-
-Ejecutar todas las pruebas anteriores:
-
- $ composer tests
-
-## ☑ Tareas pendientes
-
-- [ ] Añadir nueva funcionalidad.
-- [ ] Mejorar pruebas.
-- [ ] Mejorar documentación.
-- [ ] Refactorizar código para las reglas de estilo de código deshabilitadas. Ver [phpmd.xml](phpmd.xml) y [.php_cs.dist](.php_cs.dist).
-
-## Contribuir
-
-Si deseas colaborar, puedes echar un vistazo a la lista de
-[issues](https://github.com/Josantonius/PHP-Request/issues) o [tareas pendientes](#-tareas-pendientes).
-
-**Pull requests**
-
-* [Fork and clone](https://help.github.com/articles/fork-a-repo).
-* Ejecuta el comando `composer install` para instalar dependencias.
- Esto también instalará las [dependencias de desarrollo](https://getcomposer.org/doc/03-cli.md#install).
-* Ejecuta el comando `composer fix` para estandarizar el código.
-* Ejecuta las [pruebas](#tests).
-* Crea una nueva rama (**branch**), **commit**, **push** y envíame un
- [pull request](https://help.github.com/articles/using-pull-requests).
-
-**¡Gracias a quienes ya habéis contribuido a este proyecto!**
-
-[](https://github.com/peter279k)|[](https://github.com/Mahdrentys)|
-:---:|:---:|
-[peter279k](https://github.com/peter279k)| [Mahdrentys](https://github.com/Mahdrentys)|
-
-## Repositorio
-
-La estructura de archivos de este repositorio se creó con [PHP-Skeleton](https://github.com/Josantonius/PHP-Skeleton).
-
-## Licencia
-
-Este proyecto está licenciado bajo **licencia MIT**. Consulta el archivo [LICENSE](LICENSE) para más información.
-
-## Copyright
-
-2017 - 2018 Josantonius, [josantonius.com](https://josantonius.com/)
-
-Si te ha resultado útil, házmelo saber :wink:
-
-Puedes contactarme en [Twitter](https://twitter.com/Josantonius) o a través de mi [correo electrónico](mailto:hello@josantonius.com).
\ No newline at end of file
diff --git a/README-ES.md b/README-ES.md
index 274179b..e30d50b 100644
--- a/README-ES.md
+++ b/README-ES.md
@@ -1,8 +1,9 @@
# PHP Request library
-[![Latest Stable Version](https://poser.pugx.org/josantonius/request/v/stable)](https://packagist.org/packages/josantonius/request) [![Latest Unstable Version](https://poser.pugx.org/josantonius/request/v/unstable)](https://packagist.org/packages/josantonius/request) [![License](https://poser.pugx.org/josantonius/request/license)](LICENSE) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/aa5b98dbbc5846399bb994318dce3c88)](https://www.codacy.com/app/Josantonius/php-request?utm_source=github.com&utm_medium=referral&utm_content=Josantonius/php-request&utm_campaign=Badge_Grade) [![Total Downloads](https://poser.pugx.org/josantonius/request/downloads)](https://packagist.org/packages/josantonius/request) [![Travis](https://travis-ci.org/Josantonius/php-request.svg)](https://travis-ci.org/Josantonius/php-request) [![PSR2](https://img.shields.io/badge/PSR-2-1abc9c.svg)](http://www.php-fig.org/psr/psr-2/) [![PSR4](https://img.shields.io/badge/PSR-4-9b59b6.svg)](http://www.php-fig.org/psr/psr-4/) [![CodeCov](https://codecov.io/gh/Josantonius/php-request/branch/master/graph/badge.svg)](https://codecov.io/gh/Josantonius/php-request)
+[![Latest Stable Version](https://poser.pugx.org/josantonius/request/v/stable)](https://packagist.org/packages/josantonius/request)
+[![License](https://poser.pugx.org/josantonius/request/license)](LICENSE)
-[English version](README.md)
+[English version](README.md)
Biblioteca PHP para manejo de peticiones.
@@ -14,51 +15,48 @@ Biblioteca PHP para manejo de peticiones.
- [Cómo empezar](#cómo-empezar)
- [Uso](#uso)
- [Tests](#tests)
-- [Tareas pendientes](#-tareas-pendientes)
-- [Contribuir](#contribuir)
-- [Repositorio](#repositorio)
+- [Patrocinar](#patrocinar)
- [Licencia](#licencia)
-- [Copyright](#copyright)
---
## Requisitos
-Esta biblioteca es soportada por versiones de **PHP 7.0** o superiores.
+Esta biblioteca es soportada por PHP 7.4.
-**IMPORTANTE**: La versión 2.x no es compatible con la versión [1.x](https://github.com/Josantonius/php-request/tree/1.1.7) de esta biblioteca.
+**IMPORTANTE**: La versión 2.x no es compatible con la versión [1.x](https://github.com/Josantonius/php-request/tree/1.1.7) de esta biblioteca.
**IMPORTANTE**: La version [1.x](https://github.com/Josantonius/php-request/tree/1.1.7) se considera obsoleta, aún así, si deseas utilizarla para versiones 5.6 de PHP puedes echar un vistazo a su [documentación](https://github.com/Josantonius/php-request/tree/1.1.7).
-## Instalación
+## Instalación
La mejor forma de instalar esta extensión es a través de [Composer](http://getcomposer.org/download/).
Para instalar **PHP Request library**, simplemente escribe:
- $ composer require Josantonius/Request
+ composer require Josantonius/Request
El comando anterior sólo instalará los archivos necesarios, si prefieres **descargar todo el código fuente** puedes utilizar:
- $ composer require Josantonius/Request --prefer-source
+ composer require Josantonius/Request --prefer-source
También puedes **clonar el repositorio** completo con Git:
- $ git clone https://github.com/Josantonius/PHP-Request.git
+ $ git clone
O **instalarlo manualmente**:
Descarga [Request.php](https://raw.githubusercontent.com/Josantonius/php-request/master/src/Request.php) y [Validate.php](https://raw.githubusercontent.com/Josantonius/php-validate/master/src/Validate.php):
- $ wget https://raw.githubusercontent.com/Josantonius/php-request/master/src/Request.php
+ wget https://raw.githubusercontent.com/Josantonius/php-request/master/src/Request.php
- $ wget https://raw.githubusercontent.com/Josantonius/php-validate/master/src/Validate.php
+ wget https://raw.githubusercontent.com/Josantonius/php-validate/master/src/Validate.php
## Métodos disponibles
Métodos disponibles en esta biblioteca:
-### - Comprobar si es una petición GET:
+### - Comprobar si es una petición GET
```php
Request::isGet();
@@ -66,7 +64,7 @@ Request::isGet();
**# Return** (boolean)
-### - Comprobar si es una petición POST:
+### - Comprobar si es una petición POST
```php
Request::isPost();
@@ -74,7 +72,7 @@ Request::isPost();
**# Return** (boolean)
-### - Comprobar si es una petición PUT:
+### - Comprobar si es una petición PUT
```php
Request::isPut();
@@ -82,7 +80,7 @@ Request::isPut();
**# Return** (boolean)
-### - Comprobar si es una petición DELETE:
+### - Comprobar si es una petición DELETE
```php
Request::isDelete();
@@ -90,7 +88,7 @@ Request::isDelete();
**# Return** (boolean)
-### - Get request params.
+### - Get request params
Para peticiones PUT y DELETE se comprobará el tipo de contenido para obtener correctamente los datos recibidos en la petición.
@@ -114,7 +112,7 @@ Request::input($type);
**# Return** función anónima que devolverá el objeto Request cuando esta sea llamada
-### - Saneamiento de datos y retornar como array:
+### - Saneamiento de datos y retornar como array
```php
asArray($filters, $default);
@@ -127,7 +125,7 @@ asArray($filters, $default);
**# Return** (array) → devolverá un array vacío en caso de error
-### - Saneamiento de datos y retornar como objeto:
+### - Saneamiento de datos y retornar como objeto
```php
asObject($filters, $default);
@@ -140,7 +138,7 @@ asObject($filters, $default);
**# Return** (object) → devolverá un array vacío en caso de error
-### - Saneamiento de datos y retornar como JSON:
+### - Saneamiento de datos y retornar como JSON
```php
asJson($default);
@@ -152,7 +150,7 @@ asJson($default);
**# Return** (mixed|null) → valor, null o valor de retorno personalizado
-### - Saneamiento de datos y retornar como cadena de texto:
+### - Saneamiento de datos y retornar como cadena de texto
```php
asString($default);
@@ -164,7 +162,7 @@ asString($default);
**# Return** (mixed|null) → valor, null o valor de retorno personalizado
-### - Saneamiento de datos y retornar como entero:
+### - Saneamiento de datos y retornar como entero
```php
asInteger($default);
@@ -176,7 +174,7 @@ asInteger($default);
**# Return** (mixed|null) → valor, null o valor de retorno personalizado
-### - Saneamiento de datos y retornar como decimal:
+### - Saneamiento de datos y retornar como decimal
```php
asFloat($default);
@@ -188,7 +186,7 @@ asFloat($default);
**# Return** (mixed|null) → valor, null o valor de retorno personalizado
-### - Saneamiento de datos y retornar como booleano:
+### - Saneamiento de datos y retornar como booleano
```php
asBoolean($default);
@@ -200,7 +198,7 @@ asBoolean($default);
**# Return** (mixed|null) → valor, null o valor de retorno personalizado
-### - Saneamiento de datos y retornar como dirección IP:
+### - Saneamiento de datos y retornar como dirección IP
```php
asIp($default);
@@ -212,7 +210,7 @@ asIp($default);
**# Return** (mixed|null) → valor, null o valor de retorno personalizado
-### - Saneamiento de datos y retornar como URL:
+### - Saneamiento de datos y retornar como URL
```php
asUrl($default);
@@ -224,7 +222,7 @@ asUrl($default);
**# Return** (mixed|null) → valor, null o valor de retorno personalizado
-### - Saneamiento de datos y retornar como email:
+### - Saneamiento de datos y retornar como email
```php
asEmail($default);
@@ -260,7 +258,7 @@ use Josantonius\Validate\Validate;
Para los ejemplos se simulará que se reciben los siguientes datos en la solicitud:
-### Ejemplo de datos recibidos en la solicitud:
+### Ejemplo de datos recibidos en la solicitud
```php
'user_name' => 'John'
@@ -280,31 +278,31 @@ Para los ejemplos se simulará que se reciben los siguientes datos en la solicit
Ejemplo de uso para esta biblioteca:
-### - Comprobar si es una petición GET:
+### - Comprobar si es una petición GET
```php
Request::isGet(); // true or false
```
-### - Comprobar si es una petición POST:
+### - Comprobar si es una petición POST
```php
Request::isPost(); // true or false
```
-### - Comprobar si es una petición PUT:
+### - Comprobar si es una petición PUT
```php
Request::isPut(); // true or false
```
-### - Comprobar si es una petición DELETE:
+### - Comprobar si es una petición DELETE
```php
Request::isDelete(); // true or false
```
-### - Acceder a los parámetros de la solicitud:
+### - Acceder a los parámetros de la solicitud
```php
$_GET = Request::input('GET');
@@ -318,9 +316,9 @@ $_DELETE = Request::input('DELETE');
Devuelve una función anónima que devolverá el objeto Request cuando esta sea llamada.
-### - Array:
+### - Array
-#### - Sanear y devolver los datos como array:
+#### - Sanear y devolver los datos como array
```php
$array = $_GET()->asArray();
@@ -366,9 +364,9 @@ array(9) {
*/
```
-* [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
+- [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
-#### - Sanear, filtrar cada valor por el tipo de dato indicado y devolver como array:
+#### - Sanear, filtrar cada valor por el tipo de dato indicado y devolver como array
```php
$filters = [
@@ -394,9 +392,9 @@ var_dump($array['user_age']); // string(2) "35" (aunque se recibe un número ent
var_dump($array['user_age']); // NULL (no existe, se devuelve el valor por defecto)
```
-* [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
+- [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
-#### - Sanear todos los datos recibidos como array, filtrar cada valor según el tipo de datos y especificar un valor para cada tecla cuando sea incorrecto:
+#### - Sanear todos los datos recibidos como array, filtrar cada valor según el tipo de datos y especificar un valor para cada tecla cuando sea incorrecto
```php
$filters = [
@@ -422,11 +420,11 @@ var_dump($array['is_active']); // bool(true)
var_dump($array['is_online']); // string(0) "" (no existe, se devuelve el valor por defecto)
```
-* [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
+- [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
-### - Objeto:
+### - Objeto
-#### - Sanear y devolver los datos como objeto:
+#### - Sanear y devolver los datos como objeto
```php
$object = $_GET()->asObject();
@@ -472,9 +470,9 @@ object(stdClass)#1 (9) {
*/
```
-* [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
+- [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
-#### - Sanear, filtrar cada valor por el tipo de dato indicado y devolver como objeto:
+#### - Sanear, filtrar cada valor por el tipo de dato indicado y devolver como objeto
```php
$filters = [
@@ -500,9 +498,9 @@ var_dump($object->user_age); // int(35)
var_dump($object->user_age); // NULL (no existe, se devuelve el valor por defecto)
```
-* [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
+- [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
-#### - Sanear todos los datos recibidos como objeto, filtrar cada valor según el tipo de dato y especificar un valor para cada campo cuando sea incorrecto:
+#### - Sanear todos los datos recibidos como objeto, filtrar cada valor según el tipo de dato y especificar un valor para cada campo cuando sea incorrecto
```php
$filters = [
@@ -531,11 +529,11 @@ var_dump($object->is_online); // bool(false) (no existe, se devuelve el valor po
var_dump($object->is_member); // bool(false) (no existe, se devuelve el valor por defecto)
```
-* [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
+- [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
-### - JSON:
+### - JSON
-#### - Sanear y devolver los datos como JSON:
+#### - Sanear y devolver los datos como JSON
```php
$json = $_GET()->asJson();
@@ -555,9 +553,9 @@ string(260) "{"user_name":"John","user_surname":"Doe","user_age":35,"user_rating
*/
```
-* [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
+- [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
-#### - Obtener el valor de un campo específico, sanear los datos y devolverlos como JSON:
+#### - Obtener el valor de un campo específico, sanear los datos y devolverlos como JSON
```php
$json = $_GET('user_address')->asJson();
@@ -583,11 +581,11 @@ $json = $_DELETE('user_address')->asJson([]);
var_dump($json); // string(2) "[]" (no existe, se devuelve el valor por defecto)
```
-* [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
+- [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
-### - String:
+### - String
-#### - Obtener el valor de un campo específico, sanear los datos y devolverlos como string:
+#### - Obtener el valor de un campo específico, sanear los datos y devolverlos como string
```php
$string = $_GET('user_age')->asString();
@@ -613,11 +611,11 @@ $string = $_DELETE('user_address')->asString('unknown');
var_dump($string); // string(7) "unknown" (es un array, se devuelve el valor por defecto)
```
-* [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
+- [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
-### - Integer:
+### - Integer
-#### - Obtener el valor de un campo específico, sanear los datos y devolverlos como número entero:
+#### - Obtener el valor de un campo específico, sanear los datos y devolverlos como número entero
```php
$integer = $_GET('user_age')->asInteger();
@@ -637,11 +635,11 @@ $integer = $_DELETE('user_rating')->asInteger(5);
var_dump($integer); // int(5) (es un número decimal, se devuelve el valor por defecto)
```
-* [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
+- [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
-### - Float:
+### - Float
-#### - Obtener el valor de un campo específico, sanear los datos y devolverlos como número decimal:
+#### - Obtener el valor de un campo específico, sanear los datos y devolverlos como número decimal
```php
$float = $_GET('user_age')->asFloat();
@@ -667,11 +665,11 @@ $float = $_DELETE('user_name')->asFloat(5.5);
var_dump($float); // float(5.5) (es una cadena de texto, se devuelve el valor por defecto)
```
-* [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
+- [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
-### - Boolean:
+### - Boolean
-#### - Obtener el valor de un campo específico, sanear los datos y devolverlos como booleanos:
+#### - Obtener el valor de un campo específico, sanear los datos y devolverlos como booleanos
```php
$_GET['is_active'] = true;
@@ -749,9 +747,9 @@ $boolean = $_DELETE('is_online')->asBoolean(false);
var_dump($boolean); // bool(false) (no existe, se devuelve el valor por defecto)
```
-### - IP:
+### - IP
-#### - Obtener el valor de un campo específico, sanear los datos y devolverlos como dirección IP:
+#### - Obtener el valor de un campo específico, sanear los datos y devolverlos como dirección IP
```php
$ip = $_GET('user_ip')->asIp();
@@ -771,11 +769,11 @@ $ip = $_DELETE('user_name')->asIp("87.32.48.164");
var_dump($ip); // string(12) "87.32.48.164" (no es una IP, se devuelve el valor por defecto)
```
-* [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
+- [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
-### - URL:
+### - URL
-#### - Obtener el valor de un campo específico, sanear los datos y devolverlos como URL:
+#### - Obtener el valor de un campo específico, sanear los datos y devolverlos como URL
```php
$url = $_GET('user_website')->asUrl();
@@ -795,11 +793,11 @@ $url = $_DELETE('user_name')->asUrl("http://www.site.com/");
var_dump($url); // string(20) "http://www.site.com/" (no es una URL, se devuelve el valor por defecto)
```
-* [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
+- [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
-### - email:
+### - email
-#### - Obtener el valor de un campo específico, sanear los datos y devolverlos como email:
+#### - Obtener el valor de un campo específico, sanear los datos y devolverlos como email
```php
$email = $_GET('user_website')->asEmail();
@@ -819,35 +817,35 @@ $email = $_DELETE('user_name')->asEmail("john@site.com");
var_dump($email); // string(13) "john@site.com" (no es un correo electrónico, se devuelve el valor por defecto)
```
-* [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
+- [Ejemplo de datos recibidos en la solicitud](#ejemplo-de-datos-recibidos-en-la-solicitud)
-## Tests
+## Tests
Para ejecutar las [pruebas](tests) necesitarás [Composer](http://getcomposer.org/download/) y seguir los siguientes pasos:
- $ git clone https://github.com/Josantonius/php-request.git
+ git clone https://github.com/Josantonius/php-request.git
- $ cd php-request
+ cd php-request
- $ composer install
+ composer install
Ejecutar pruebas unitarias con [PHPUnit](https://phpunit.de/):
- $ gnome-terminal -e 'php -S localhost:8000 -t tests/'
+ gnome-terminal -e 'php -S localhost:8000 -t tests/'
- $ composer phpunit
+ composer phpunit
Ejecutar pruebas de estándares de código [PSR2](http://www.php-fig.org/psr/psr-2/) con [PHPCS](https://github.com/squizlabs/PHP_CodeSniffer):
- $ composer phpcs
+ composer phpcs
Ejecutar pruebas con [PHP Mess Detector](https://phpmd.org/) para detectar inconsistencias en el estilo de codificación:
- $ composer phpmd
+ composer phpmd
Ejecutar todas las pruebas anteriores:
- $ composer tests
+ composer tests
## ☑ Tareas pendientes
@@ -867,12 +865,12 @@ Si deseas colaborar, puedes echar un vistazo a la lista de
**Pull requests**
-* [Fork and clone](https://help.github.com/articles/fork-a-repo).
-* Ejecuta el comando `composer install` para instalar dependencias.
+- [Fork and clone](https://help.github.com/articles/fork-a-repo).
+- Ejecuta el comando `composer install` para instalar dependencias.
Esto también instalará las [dependencias de desarrollo](https://getcomposer.org/doc/03-cli.md#install).
-* Ejecuta el comando `composer fix` para estandarizar el código.
-* Ejecuta las [pruebas](#tests).
-* Crea una nueva rama (**branch**), **commit**, **push** y envíame un
+- Ejecuta el comando `composer fix` para estandarizar el código.
+- Ejecuta las [pruebas](#tests).
+- Crea una nueva rama (**branch**), **commit**, **push** y envíame un
[pull request](https://help.github.com/articles/using-pull-requests).
**¡Gracias a quienes ya habéis contribuido a este proyecto!**
@@ -895,4 +893,16 @@ Este proyecto está licenciado bajo **licencia MIT**. Consulta el archivo [LICEN
Si te ha resultado útil, házmelo saber :wink:
-Puedes contactarme en [Twitter](https://twitter.com/Josantonius) o a través de mi [correo electrónico](mailto:hello@josantonius.com).
\ No newline at end of file
+Puedes contactarme en [Twitter](https://twitter.com/Josantonius) o a través de mi [correo electrónico](mailto:hello@josantonius.com).
+
+## Patrocinar
+
+Si este proyecto te ayuda a reducir el tiempo de desarrollo,
+[puedes patrocinarme](https://github.com/josantonius/lang/es-ES/README.md#patrocinar)
+para apoyar mi trabajo :blush:
+
+## Licencia
+
+Este repositorio tiene una licencia [MIT License](LICENSE).
+
+Copyright © XXXX, [Josantonius](https://github.com/josantonius/lang/es-ES/README.md#contacto)
diff --git a/README.md b/README.md
index 95c8f00..d748a46 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,11 @@
# PHP Request library
-[![Latest Stable Version](https://poser.pugx.org/josantonius/request/v/stable)](https://packagist.org/packages/josantonius/request) [![Latest Unstable Version](https://poser.pugx.org/josantonius/request/v/unstable)](https://packagist.org/packages/josantonius/request) [![License](https://poser.pugx.org/josantonius/request/license)](LICENSE) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/aa5b98dbbc5846399bb994318dce3c88)](https://www.codacy.com/app/Josantonius/php-request?utm_source=github.com&utm_medium=referral&utm_content=Josantonius/php-request&utm_campaign=Badge_Grade) [![Total Downloads](https://poser.pugx.org/josantonius/request/downloads)](https://packagist.org/packages/josantonius/request) [![Travis](https://travis-ci.org/Josantonius/php-request.svg)](https://travis-ci.org/Josantonius/php-request) [![PSR2](https://img.shields.io/badge/PSR-2-1abc9c.svg)](http://www.php-fig.org/psr/psr-2/) [![PSR4](https://img.shields.io/badge/PSR-4-9b59b6.svg)](http://www.php-fig.org/psr/psr-4/) [![CodeCov](https://codecov.io/gh/Josantonius/php-request/branch/master/graph/badge.svg)](https://codecov.io/gh/Josantonius/php-request)
+[![Latest Stable Version](https://poser.pugx.org/josantonius/request/v/stable)](https://packagist.org/packages/josantonius/request)
+[![License](https://poser.pugx.org/josantonius/request/license)](LICENSE)
[Versión en español](README-ES.md)
-PHP library for handling requests.
+PHP library for handling requests.
---
@@ -14,19 +15,16 @@ PHP library for handling requests.
- [Quick Start](#quick-start)
- [Usage](#usage)
- [Tests](#tests)
-- [TODO](#-todo)
-- [Contribute](#contribute)
-- [Repository](#repository)
+- [Sponsor](#Sponsor)
- [License](#license)
-- [Copyright](#copyright)
---
## Requirements
-This library is supported by **PHP versions 7.0** or higher.
+This library is supported by PHP 7.4.
-**IMPORTANT**: Version 2.x does not support version [1.x](https://github.com/Josantonius/php-request/tree/1.1.7) of this library.
+**IMPORTANT**: Version 2.x does not support version [1.x](https://github.com/Josantonius/php-request/tree/1.1.7) of this library.
**IMPORTANT**: Version [1.x](https://github.com/Josantonius/php-request/tree/1.1.7) has been considered obsolete, but if you want to use it for 5.6 versions of PHP you can have a look at its [documentation](https://github.com/Josantonius/php-request/tree/1.1.7).
@@ -36,29 +34,29 @@ The preferred way to install this extension is through [Composer](http://getcomp
To install **PHP Request library**, simply:
- $ composer require josantonius/request
+ composer require josantonius/request
The previous command will only install the necessary files, if you prefer to **download the entire source code** you can use:
- $ composer require josantonius/request --prefer-source
+ composer require josantonius/request --prefer-source
You can also **clone the complete repository** with Git:
- $ git clone https://github.com/Josantonius/php-request.git
+ $ git clone
Or **install it manually**:
Download [Request.php](https://raw.githubusercontent.com/Josantonius/php-request/master/src/Request.php) and [Validate.php](https://raw.githubusercontent.com/Josantonius/php-validate/master/src/Validate.php):
- $ wget https://raw.githubusercontent.com/Josantonius/php-request/master/src/Request.php
+ wget https://raw.githubusercontent.com/Josantonius/php-request/master/src/Request.php
- $ wget https://raw.githubusercontent.com/Josantonius/php-validate/master/src/Validate.php
+ wget https://raw.githubusercontent.com/Josantonius/php-validate/master/src/Validate.php
## Available Methods
Available methods in this library:
-### - Check if it's a GET request:
+### - Check if it's a GET request
```php
Request::isGet();
@@ -66,7 +64,7 @@ Request::isGet();
**# Return** (boolean)
-### - Check if it's a POST request:
+### - Check if it's a POST request
```php
Request::isPost();
@@ -74,7 +72,7 @@ Request::isPost();
**# Return** (boolean)
-### - Check if it's a PUT request:
+### - Check if it's a PUT request
```php
Request::isPut();
@@ -82,7 +80,7 @@ Request::isPut();
**# Return** (boolean)
-### - Check if it's a DELETE request:
+### - Check if it's a DELETE request
```php
Request::isDelete();
@@ -90,7 +88,7 @@ Request::isDelete();
**# Return** (boolean)
-### - Get request params.
+### - Get request params
For PUT and DELETE requests, the content type will be checked to correctly obtain the data received in the request.
@@ -114,7 +112,7 @@ Request::input($type);
**# Return** anonymous function that will return the Request object when it's called
-### - Data sanitation and return as array:
+### - Data sanitation and return as array
```php
asArray($filters, $default);
@@ -127,7 +125,7 @@ asArray($filters, $default);
**# Return** (array) → it will return an empty array in case of error
-### - Data sanitation and return as object:
+### - Data sanitation and return as object
```php
asObject($filters, $default);
@@ -140,7 +138,7 @@ asObject($filters, $default);
**# Return** (object) → it will return an empty object in case of error
-### - Data sanitation and return as JSON:
+### - Data sanitation and return as JSON
```php
asJson($default);
@@ -152,7 +150,7 @@ asJson($default);
**# Return** (mixed|null) → value, null or customized return value
-### - Data sanitation and return as string:
+### - Data sanitation and return as string
```php
asString($default);
@@ -164,7 +162,7 @@ asString($default);
**# Return** (mixed|null) → value, null or customized return value
-### - Data sanitation and return as integer:
+### - Data sanitation and return as integer
```php
asInteger($default);
@@ -176,7 +174,7 @@ asInteger($default);
**# Return** (mixed|null) → value, null or customized return value
-### - Data sanitation and return as float:
+### - Data sanitation and return as float
```php
asFloat($default);
@@ -188,7 +186,7 @@ asFloat($default);
**# Return** (mixed|null) → value, null or customized return value
-### - Data sanitation and return as boolean:
+### - Data sanitation and return as boolean
```php
asBoolean($default);
@@ -200,7 +198,7 @@ asBoolean($default);
**# Return** (mixed|null) → value, null or customized return value
-### - Data sanitation and return as IP address:
+### - Data sanitation and return as IP address
```php
asIp($default);
@@ -212,7 +210,7 @@ asIp($default);
**# Return** (mixed|null) → value, null or customized return value
-### - Data sanitation and return as URL:
+### - Data sanitation and return as URL
```php
asUrl($default);
@@ -224,7 +222,7 @@ asUrl($default);
**# Return** (mixed|null) → value, null or customized return value
-### - Data sanitation and return as email:
+### - Data sanitation and return as email
```php
asEmail($default);
@@ -260,7 +258,7 @@ use Josantonius\Validate\Validate;
For the examples it will be simulated that the following data is received in the request:
-### Example data received in the request:
+### Example data received in the request
```php
'user_name' => 'John'
@@ -280,31 +278,31 @@ For the examples it will be simulated that the following data is received in the
Example of use for this library:
-### - Check if it's a GET request:
+### - Check if it's a GET request
```php
Request::isGet(); // true or false
```
-### - Check if it's a POST request:
+### - Check if it's a POST request
```php
Request::isPost(); // true or false
```
-### - Check if it's a PUT request:
+### - Check if it's a PUT request
```php
Request::isPut(); // true or false
```
-### - Check if it's a DELETE request:
+### - Check if it's a DELETE request
```php
Request::isDelete(); // true or false
```
-### - Access to the parameters of the request.
+### - Access to the parameters of the request
```php
$_GET = Request::input('GET');
@@ -318,9 +316,9 @@ $_DELETE = Request::input('DELETE');
Returns an anonymous function that will return the Request object when it's called.
-### - As array:
+### - As array
-#### - Get and sanitize all data and return them as array:
+#### - Get and sanitize all data and return them as array
```php
$array = $_GET()->asArray();
@@ -366,9 +364,9 @@ array(9) {
*/
```
-* [Example data received in the request](#example-data-received-in-the-request)
+- [Example data received in the request](#example-data-received-in-the-request)
-#### - Obtain, sanitize all data and return them as array and filter each value according to the data type:
+#### - Obtain, sanitize all data and return them as array and filter each value according to the data type
```php
$filters = [
@@ -394,9 +392,9 @@ var_dump($array['user_age']); // string(2) "35" (although an integer is received
var_dump($array['user_age']); // NULL (doesn't exist, the default value is returned)
```
-* [Example data received in the request](#example-data-received-in-the-request)
+- [Example data received in the request](#example-data-received-in-the-request)
-#### - Obtain, sanitize all data and return them as array, filter each value according to the data type and specify a value for each key when it's wrong:
+#### - Obtain, sanitize all data and return them as array, filter each value according to the data type and specify a value for each key when it's wrong
```php
$filters = [
@@ -422,11 +420,11 @@ var_dump($array['is_active']); // bool(true)
var_dump($array['is_online']); // string(0) "" (doesn't exist, the default value is returned)
```
-* [Example data received in the request](#example-data-received-in-the-request)
+- [Example data received in the request](#example-data-received-in-the-request)
-### - As object:
+### - As object
-#### - Get and sanitize all data and return them as object:
+#### - Get and sanitize all data and return them as object
```php
$object = $_GET()->asObject();
@@ -472,9 +470,9 @@ object(stdClass)#1 (9) {
*/
```
-* [Example data received in the request](#example-data-received-in-the-request)
+- [Example data received in the request](#example-data-received-in-the-request)
-#### - Obtain, sanitize all data and return them as object and filter each value according to the data type:
+#### - Obtain, sanitize all data and return them as object and filter each value according to the data type
```php
$filters = [
@@ -500,9 +498,9 @@ var_dump($object->user_age); // int(35)
var_dump($object->user_age); // NULL (doesn't exist, the default value is returned)
```
-* [Example data received in the request](#example-data-received-in-the-request)
+- [Example data received in the request](#example-data-received-in-the-request)
-#### - Obtain, sanitize all data and return them as object, filter each value according to the data type and specify a value for each key when it's wrong:
+#### - Obtain, sanitize all data and return them as object, filter each value according to the data type and specify a value for each key when it's wrong
```php
$filters = [
@@ -531,11 +529,11 @@ var_dump($object->is_online); // bool(false) (doesn't exist, the default value i
var_dump($object->is_member); // bool(false) (doesn't exist, the default value is returned)
```
-* [Example data received in the request](#example-data-received-in-the-request)
+- [Example data received in the request](#example-data-received-in-the-request)
-### - As JSON:
+### - As JSON
-#### - Get and sanitize all data and return them as JSON:
+#### - Get and sanitize all data and return them as JSON
```php
$json = $_GET()->asJson();
@@ -555,9 +553,9 @@ string(260) "{"user_name":"John","user_surname":"Doe","user_age":35,"user_rating
*/
```
-* [Example data received in the request](#example-data-received-in-the-request)
+- [Example data received in the request](#example-data-received-in-the-request)
-#### - Get specific key value, sanitize data and return them as JSON:
+#### - Get specific key value, sanitize data and return them as JSON
```php
$json = $_GET('user_address')->asJson();
@@ -583,11 +581,11 @@ $json = $_DELETE('user_address')->asJson([]);
var_dump($json); // string(2) "[]" (doesn't exist, the default value is returned)
```
-* [Example data received in the request](#example-data-received-in-the-request)
+- [Example data received in the request](#example-data-received-in-the-request)
-### - As string:
+### - As string
-#### - Get specific key value, sanitize data and return them as string:
+#### - Get specific key value, sanitize data and return them as string
```php
$string = $_GET('user_age')->asString();
@@ -613,11 +611,11 @@ $string = $_DELETE('user_address')->asString('unknown');
var_dump($string); // string(7) "unknown" (it's an array, the default value is returned)
```
-* [Example data received in the request](#example-data-received-in-the-request)
+- [Example data received in the request](#example-data-received-in-the-request)
-### - As integer:
+### - As integer
-#### - Get specific key value, sanitize data and return them as integer:
+#### - Get specific key value, sanitize data and return them as integer
```php
$integer = $_GET('user_age')->asInteger();
@@ -637,11 +635,11 @@ $integer = $_DELETE('user_rating')->asInteger(5);
var_dump($integer); // int(5) (it's a float, the default value is returned)
```
-* [Example data received in the request](#example-data-received-in-the-request)
+- [Example data received in the request](#example-data-received-in-the-request)
-### - As float:
+### - As float
-#### - Get specific key value, sanitize data and return them as float:
+#### - Get specific key value, sanitize data and return them as float
```php
$float = $_GET('user_age')->asFloat();
@@ -667,11 +665,11 @@ $float = $_DELETE('user_name')->asFloat(5.5);
var_dump($float); // float(5.5) (it's a string, the default value is returned)
```
-* [Example data received in the request](#example-data-received-in-the-request)
+- [Example data received in the request](#example-data-received-in-the-request)
-### - As boolean:
+### - As boolean
-#### - Get specific key value, sanitize data and return them as boolean:
+#### - Get specific key value, sanitize data and return them as boolean
```php
$_GET['is_active'] = true;
@@ -749,9 +747,9 @@ $boolean = $_DELETE('is_online')->asBoolean(false);
var_dump($boolean); // bool(false) (doesn't exist, the default value is returned)
```
-### - As IP:
+### - As IP
-#### - Get specific key value, sanitize data and return them as IP:
+#### - Get specific key value, sanitize data and return them as IP
```php
$ip = $_GET('user_ip')->asIp();
@@ -771,11 +769,13 @@ $ip = $_DELETE('user_name')->asIp("87.32.48.164");
var_dump($ip); // string(12) "87.32.48.164" (it's not an IP, the default value is returned)
```
-* [Example data received in the request](#example-data-received-in-the-request)
+- [Example data received in the request](#example-data-received-in-the-request)
-### - As URL:
+### - As URL
-#### - Get specific key value, sanitize data and return them as URL:
+filterRequest
+
+#### - Get specific key value, sanitize data and return them as URL
```php
$url = $_GET('user_website')->asUrl();
@@ -795,11 +795,11 @@ $url = $_DELETE('user_name')->asUrl("http://www.site.com/");
var_dump($url); // string(20) "http://www.site.com/" (it's not an URL, the default value is returned)
```
-* [Example data received in the request](#example-data-received-in-the-request)
+- [Example data received in the request](#example-data-received-in-the-request)
-### - As email:
+### - As email
-#### - Get specific key value, sanitize data and return them as email:
+#### - Get specific key value, sanitize data and return them as email
```php
$email = $_GET('user_website')->asEmail();
@@ -819,80 +819,43 @@ $email = $_DELETE('user_name')->asEmail("john@site.com");
var_dump($email); // string(13) "john@site.com" (it's not an email, the default value is returned)
```
-* [Example data received in the request](#example-data-received-in-the-request)
+- [Example data received in the request](#example-data-received-in-the-request)
-## Tests
+## Tests
To run [tests](tests) you just need [composer](http://getcomposer.org/download/) and to execute the following:
- $ git clone https://github.com/Josantonius/php-request.git
+ git clone https://github.com/Josantonius/php-request.git
- $ cd php-request
+ cd php-request
- $ composer install
+ composer install
Run unit tests with [PHPUnit](https://phpunit.de/):
- $ gnome-terminal -e 'php -S localhost:8000 -t tests/'
+ gnome-terminal -e 'php -S localhost:8000 -t tests/'
- $ composer phpunit
+ composer phpunit
Run [PSR2](http://www.php-fig.org/psr/psr-2/) code standard tests with [PHPCS](https://github.com/squizlabs/PHP_CodeSniffer):
- $ composer phpcs
+ composer phpcs
Run [PHP Mess Detector](https://phpmd.org/) tests to detect inconsistencies in code style:
- $ composer phpmd
+ composer phpmd
Run all previous tests:
- $ composer tests
-
-## ☑ TODO
-
-- [ ] Add new feature.
-- [ ] Improve tests.
-- [ ] Improve documentation.
-- [ ] Refactor code for disabled code style rules. See [phpmd.xml](phpmd.xml) and [.php_cs.dist](.php_cs.dist).
-- [ ] Stop exclusion of test files in [.php_cs.dist](.php_cs.dist).
-- [ ] Change the `getParsedInput` method to public, create tests and document it.
-- [ ] Change the `getContentType` method to public, create tests and document it.
-- [ ] Change the `parseRaw` method to public, create tests and document it.
-
-## Contribute
-
-If you would like to help, please take a look at the list of
-[issues](https://github.com/Josantonius/php-request/issues) or the [To Do](#-todo) checklist.
-
-**Pull requests**
+ composer tests
-* [Fork and clone](https://help.github.com/articles/fork-a-repo).
-* Run the command `composer install` to install the dependencies.
- This will also install the [dev dependencies](https://getcomposer.org/doc/03-cli.md#install).
-* Run the command `composer fix` to excute code standard fixers.
-* Run the [tests](#tests).
-* Create a **branch**, **commit**, **push** and send me a
- [pull request](https://help.github.com/articles/using-pull-requests).
+## Sponsor
-**Thank you to all the people who already contributed to this project!**
-
-[](https://github.com/peter279k)|[](https://github.com/Mahdrentys)|
-:---:|:---:|
-[peter279k](https://github.com/peter279k)| [Mahdrentys](https://github.com/Mahdrentys)|
-
-## Repository
-
-The file structure from this repository was created with [PHP-Skeleton](https://github.com/Josantonius/PHP-Skeleton).
+If this project helps you to reduce your development time,
+[you can sponsor me](https://github.com/josantonius#sponsor) to support my open source work :blush:
## License
-This project is licensed under **MIT license**. See the [LICENSE](LICENSE) file for more info.
-
-## Copyright
-
-2017 - 2018 Josantonius, [josantonius.com](https://josantonius.com/)
-
-If you find it useful, let me know :wink:
+This repository is licensed under the [MIT License](LICENSE).
-You can contact me on [Twitter](https://twitter.com/Josantonius) or through my [email](mailto:hello@josantonius.com).
+Copyright © 2017-2022, [Josantonius](https://github.com/josantonius#contact)
diff --git a/composer.json b/composer.json
index 9677d01..0843f89 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,6 @@
{
- "name": "josantonius/request",
- "type": "library",
+ "name": "josantonius/request",
+ "type": "library",
"description": "PHP library for handling requests.",
"keywords": [
"Request",
@@ -15,15 +15,15 @@
"license": "MIT",
"authors": [
{
- "name": "Josantonius",
- "email": "hello@josantonius.com",
+ "name": "Josantonius",
+ "email": "hello@josantonius.com",
"homepage": "https://josantonius.com",
- "role": "Developer"
+ "role": "Developer"
}
],
"support": {
"issues": "https://github.com/josantonius/php-request/issues",
- "forum": "http://stackoverflow.com/tags/josantonius/php-request",
+ "forum": "http://stackoverflow.com/tags/josantonius/php-request",
"source": "https://github.com/josantonius/php-request"
},
"config": {
@@ -31,7 +31,7 @@
},
"minimum-stability": "stable",
"require": {
- "php": "^7.0",
+ "php": "^7.4",
"josantonius/validate": "^1.0"
},
"require-dev": {
@@ -73,4 +73,4 @@
"@phpunit"
]
}
-}
+}
\ No newline at end of file
diff --git a/src/Request.php b/src/Request.php
index 4b7c2ac..d7cafdc 100644
--- a/src/Request.php
+++ b/src/Request.php
@@ -11,6 +11,7 @@
* @link https://github.com/Josantonius/PHP-Request
* @since 1.0.0
*/
+
namespace Josantonius\Request;
use Josantonius\Validate\Validate;
@@ -86,7 +87,7 @@ public static function input(string $type)
* @param array $filters → associative array with data type for each key
* @param mixed $default → default value for non-existent or incorrect keys
*/
- public function asArray(array $filters = [], $default = null) : array
+ public function asArray(array $filters = [], $default = null): array
{
$array = Validate::asArray($this->params[$this->key] ?? $this->params, []);
@@ -106,7 +107,7 @@ public function asArray(array $filters = [], $default = null) : array
* @param array $filters → object with data type for each key
* @param mixed $default → default value for non-existent or incorrect keys
*/
- public function asObject(array $filters = [], $default = null) : \stdClass
+ public function asObject(array $filters = [], $default = null): \stdClass
{
$object = Validate::asObject($this->params[$this->key] ?? $this->params, (object) []);
@@ -230,10 +231,24 @@ public function asEmail($default = null)
return Validate::asEmail($this->params[$this->key] ?? null, $default);
}
+ /**
+ * Data sanitation and return as email.
+ *
+ * @since 2.0.1
+ *
+ * @param mixed $default → default value
+ *
+ * @return mixed → value, null or customized return value
+ */
+ public function asDatetime($default = null)
+ {
+ return Validate::asDatetime($this->params[$this->key] ?? null, $default);
+ }
+
/**
* Check if it is a GET request.
*/
- public static function isGet() : bool
+ public static function isGet(): bool
{
return $_SERVER['REQUEST_METHOD'] === 'GET';
}
@@ -241,7 +256,7 @@ public static function isGet() : bool
/**
* Check if it is a POST request.
*/
- public static function isPost() : bool
+ public static function isPost(): bool
{
return $_SERVER['REQUEST_METHOD'] === 'POST';
}
@@ -249,7 +264,7 @@ public static function isPost() : bool
/**
* Check if it is a PUT request.
*/
- public static function isPut() : bool
+ public static function isPut(): bool
{
return $_SERVER['REQUEST_METHOD'] === 'PUT';
}
@@ -257,7 +272,7 @@ public static function isPut() : bool
/**
* Check if it is a DELETE request.
*/
- public static function isDelete() : bool
+ public static function isDelete(): bool
{
return $_SERVER['REQUEST_METHOD'] === 'DELETE';
}
@@ -297,7 +312,7 @@ private static function getParsedInput()
*
* @since 2.0.0
*/
- private static function getContentType() : string
+ private static function getContentType(): string
{
$contentType = $_SERVER['HTTP_CONTENT_TYPE'] ?? '';
diff --git a/tests/PostRequestProxy.php b/tests/PostRequestProxy.php
index ce34df3..37d3f52 100644
--- a/tests/PostRequestProxy.php
+++ b/tests/PostRequestProxy.php
@@ -1,4 +1,5 @@