Is a library for prioritizing or verifying Get, Post and Raw inputs.
- PHP 7.2 or later
- InitPHP ParameterBag
- InitPHP Validation
composer require initphp/input
Example :
require_once "vendor/autoload.php";
use \InitPHP\Input\Facade\Inputs as Input;
// echo isset($_GET['name']) ? $_GET['name'] : 'John';
echo Input::get('name', 'John');
Example :
require_once "vendor/autoload.php";
use \InitPHP\Input\Facade\Inputs as Input;
/**
* if(isset($_GET['year']) && $_GET['year'] >= 1970 && $_GET['year'] <= 2070){
* $year = $_GET['year'];
* }elseif(isset($_POST['year']) && $_POST['year'] >= 1970 && $_POST['year'] <= 2070){
* $year = $_POST['year'];
* }else{
* $year = 2015;
* }
*/
$year = Input::getPost('year', 2015, ['range(1970...2070)']);
Example :
require_once "vendor/autoload.php";
use \InitPHP\Input\Facade\Inputs as Input;
/**
* if(isset($_POST['password']) && isset($_POST['password_retype']) && !empty($_POST['password']) && $_POST['password'] == $_POST['password_retype']){
* $password = $_POST['password'];
* }else{
* $password = null;
* }
*/
$password = Input::post('password', null, ['required', 'again(password_retype)'])
public function get(string $key, mixed $default = null, ?array $validation = null): mixed;
public function post(string $key, mixed $default = null, ?array $validation = null): mixed;
Data from reading php://input
.
public function raw(string $key, mixed $default = null, ?array $validation = null): mixed;
$_GET
-> $_POST
public function getPost(string $key, mixed $default = null, ?array $validation = null): mixed;
$_GET
-> php://input
public function getRaw(string $key, mixed $default = null, ?array $validation = null): mixed;
$_GET
-> $_POST
-> php://input
public function getPostRaw(string $key, mixed $default = null, ?array $validation = null): mixed;
$_GET
-> php://input
-> $_POST
public function getRawPost(string $key, mixed $default = null, ?array $validation = null): mixed;
$_POST
-> $_GET
public function postGet(string $key, mixed $default = null, ?array $validation = null): mixed;
$_POST
-> php://input
public function postRaw(string $key, mixed $default = null, ?array $validation = null): mixed;
$_POST
-> $_GET
-> php://input
public function postGetRaw(string $key, mixed $default = null, ?array $validation = null): mixed;
$_POST
-> php://input
-> $_GET
public function postRawGet(string $key, mixed $default = null, ?array $validation = null): mixed;
php://input
-> $_GET
public function rawGet(string $key, mixed $default = null, ?array $validation = null): mixed;
php://input
-> $_POST
public function rawPost(string $key, mixed $default = null, ?array $validation = null): mixed;
php://input
-> $_GET
-> $_POST
public function rawGetPost(string $key, mixed $default = null, ?array $validation = null): mixed;
php://input
-> $_POST
-> $_GET
public function rawPostGet(string $key, mixed $default = null, ?array $validation = null): mixed;
Checks to see if the requested entry has been declared.
It does something like isset($_GET['key'])
, case-insensitively.
public function hasGet(string $key): bool;
It does something like isset($_POST['key'])
, case-insensitively.
public function hasPost(string $key): bool;
Case-insensitively, it queries the body inputs for a key value.
public function hasRaw(string $key): bool;
Copyright © 2022 MIT License