https://github.com/initphp/input
It is a simple library developed to retrieve user inputs by prioritizing or verifying.
https://github.com/initphp/input
input input-validation input-validator php
Last synced: about 1 year ago
JSON representation
It is a simple library developed to retrieve user inputs by prioritizing or verifying.
- Host: GitHub
- URL: https://github.com/initphp/input
- Owner: InitPHP
- License: mit
- Created: 2022-03-15T09:32:57.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-24T13:04:47.000Z (about 3 years ago)
- Last Synced: 2025-01-26T03:13:46.962Z (about 1 year ago)
- Topics: input, input-validation, input-validator, php
- Language: PHP
- Homepage:
- Size: 13.7 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# InitPHP Input
Is a library for prioritizing or verifying Get, Post and Raw inputs.
[](https://packagist.org/packages/initphp/input) [](https://packagist.org/packages/initphp/input) [](https://packagist.org/packages/initphp/input) [](https://packagist.org/packages/initphp/input) [](https://packagist.org/packages/initphp/input)
## Requirements
- PHP 7.2 or later
- [InitPHP ParameterBag](https://github.com/InitPHP/ParameterBag)
- [InitPHP Validation](https://github.com/InitPHP/Validation)
## Installation
```
composer require initphp/input
```
## Usage
**Example :**
```php
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 :**
```php
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 :**
```php
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)'])
```
## Methods
#### `Inputs::get()`
```php
public function get(string $key, mixed $default = null, ?array $validation = null): mixed;
```
#### `Inputs::post()`
```php
public function post(string $key, mixed $default = null, ?array $validation = null): mixed;
```
#### `Inputs::raw()`
Data from reading `php://input`.
```php
public function raw(string $key, mixed $default = null, ?array $validation = null): mixed;
```
### Getting Input with Priority
#### `Inputs::getPost()`
`$_GET` -> `$_POST`
```php
public function getPost(string $key, mixed $default = null, ?array $validation = null): mixed;
```
#### `Inputs::getRaw()`
`$_GET` -> `php://input`
```php
public function getRaw(string $key, mixed $default = null, ?array $validation = null): mixed;
```
#### `Inputs::getPostRaw()`
`$_GET` -> `$_POST` -> `php://input`
```php
public function getPostRaw(string $key, mixed $default = null, ?array $validation = null): mixed;
```
#### `Inputs::getRawPost()`
`$_GET` -> `php://input` -> `$_POST`
```php
public function getRawPost(string $key, mixed $default = null, ?array $validation = null): mixed;
```
#### `Inputs::postGet()`
`$_POST` -> `$_GET`
```php
public function postGet(string $key, mixed $default = null, ?array $validation = null): mixed;
```
#### `Inputs::postRaw()`
`$_POST` -> `php://input`
```php
public function postRaw(string $key, mixed $default = null, ?array $validation = null): mixed;
```
#### `Inputs::postGetRaw()`
`$_POST` -> `$_GET` -> `php://input`
```php
public function postGetRaw(string $key, mixed $default = null, ?array $validation = null): mixed;
```
#### `Inputs::postRawGet()`
`$_POST` -> `php://input` -> `$_GET`
```php
public function postRawGet(string $key, mixed $default = null, ?array $validation = null): mixed;
```
#### `Inputs::rawGet()`
`php://input` -> `$_GET`
```php
public function rawGet(string $key, mixed $default = null, ?array $validation = null): mixed;
```
#### `Inputs::rawPost()`
`php://input` -> `$_POST`
```php
public function rawPost(string $key, mixed $default = null, ?array $validation = null): mixed;
```
#### `Inputs::rawGetPost()`
`php://input` -> `$_GET` -> `$_POST`
```php
public function rawGetPost(string $key, mixed $default = null, ?array $validation = null): mixed;
```
#### `Inputs::rawPostGet()`
`php://input` -> `$_POST` -> `$_GET`
```php
public function rawPostGet(string $key, mixed $default = null, ?array $validation = null): mixed;
```
### Has it been declared?
Checks to see if the requested entry has been declared.
#### `Inputs::hasGet()`
It does something like `isset($_GET['key'])` , case-insensitively.
```php
public function hasGet(string $key): bool;
```
#### `Inputs::hasPost()`
It does something like `isset($_POST['key'])` , case-insensitively.
```php
public function hasPost(string $key): bool;
```
#### `Inputs::hasRaw()`
Case-insensitively, it queries the body inputs for a key value.
```php
public function hasRaw(string $key): bool;
```
## Credits
- [Muhammet ŞAFAK](https://www.muhammetsafak.com.tr) <>
## License
Copyright © 2022 [MIT License](./LICENSE)