Skip to content

Commit

Permalink
ParameterBag is kept with static property.
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammetsafak committed Jul 25, 2022
1 parent b79f4f0 commit 8e2abd9
Show file tree
Hide file tree
Showing 5 changed files with 311 additions and 297 deletions.
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# InitPHP Input

It is a simple library developed to retrieve user inputs by prioritizing or verifying.
Is a library for prioritizing or verifying Get, Post and Raw inputs.

[![Latest Stable Version](http://poser.pugx.org/initphp/input/v)](https://packagist.org/packages/initphp/input) [![Total Downloads](http://poser.pugx.org/initphp/input/downloads)](https://packagist.org/packages/initphp/input) [![Latest Unstable Version](http://poser.pugx.org/initphp/input/v/unstable)](https://packagist.org/packages/initphp/input) [![License](http://poser.pugx.org/initphp/input/license)](https://packagist.org/packages/initphp/input) [![PHP Version Require](http://poser.pugx.org/initphp/input/require/php)](https://packagist.org/packages/initphp/input)


## Requirements

- PHP 7.4 or higher
- PHP 7.2 or later
- [InitPHP ParameterBag](https://github.com/InitPHP/ParameterBag)
- [InitPHP Validation](https://github.com/InitPHP/Validation)

Expand All @@ -23,7 +23,7 @@ composer require initphp/input

```php
require_once "vendor/autoload.php";
use \InitPHP\Input\Input;
use \InitPHP\Input\Facede\Inputs as Input;

// echo isset($_GET['name']) ? $_GET['name'] : 'John';
echo Input::get('name', 'John');
Expand All @@ -33,7 +33,7 @@ echo Input::get('name', 'John');

```php
require_once "vendor/autoload.php";
use \InitPHP\Input\Input;
use \InitPHP\Input\Facede\Inputs as Input;

/**
* if(isset($_GET['year']) && $_GET['year'] >= 1970 && $_GET['year'] <= 2070){
Expand All @@ -51,7 +51,7 @@ $year = Input::getPost('year', 2015, ['range(1970...2070)']);

```php
require_once "vendor/autoload.php";
use \InitPHP\Input\Input;
use \InitPHP\Input\Facede\Inputs as Input;

/**
* if(isset($_POST['password']) && isset($_POST['password_retype']) && !empty($_POST['password']) && $_POST['password'] == $_POST['password_retype']){
Expand All @@ -66,19 +66,19 @@ $password = Input::post('password', null, ['required', 'again(password_retype)']

## Methods

#### `Input::get()`
#### `Inputs::get()`

```php
public function get(string $key, mixed $default = null, ?array $validation = null): mixed;
```

#### `Input::post()`
#### `Inputs::post()`

```php
public function post(string $key, mixed $default = null, ?array $validation = null): mixed;
```

#### `Input::raw()`
#### `Inputs::raw()`

Data from reading `php://input`.

Expand All @@ -88,95 +88,95 @@ public function raw(string $key, mixed $default = null, ?array $validation = nul

### Getting Input with Priority

#### `Input::getPost()`
#### `Inputs::getPost()`

`$_GET` -> `$_POST`

```php
public function getPost(string $key, mixed $default = null, ?array $validation = null): mixed;
```

#### `Input::getRaw()`
#### `Inputs::getRaw()`

`$_GET` -> `php://input`

```php
public function getRaw(string $key, mixed $default = null, ?array $validation = null): mixed;
```

#### `Input::getPostRaw()`
#### `Inputs::getPostRaw()`

`$_GET` -> `$_POST` -> `php://input`

```php
public function getPostRaw(string $key, mixed $default = null, ?array $validation = null): mixed;
```

#### `Input::getRawPost()`
#### `Inputs::getRawPost()`

`$_GET` -> `php://input` -> `$_POST`

```php
public function getRawPost(string $key, mixed $default = null, ?array $validation = null): mixed;
```

#### `Input::postGet()`
#### `Inputs::postGet()`

`$_POST` -> `$_GET`

```php
public function postGet(string $key, mixed $default = null, ?array $validation = null): mixed;
```

#### `Input::postRaw()`
#### `Inputs::postRaw()`

`$_POST` -> `php://input`

```php
public function postRaw(string $key, mixed $default = null, ?array $validation = null): mixed;
```

#### `Input::postGetRaw()`
#### `Inputs::postGetRaw()`

`$_POST` -> `$_GET` -> `php://input`

```php
public function postGetRaw(string $key, mixed $default = null, ?array $validation = null): mixed;
```

#### `Input::postRawGet()`
#### `Inputs::postRawGet()`

`$_POST` -> `php://input` -> `$_GET`

```php
public function postRawGet(string $key, mixed $default = null, ?array $validation = null): mixed;
```

#### `Input::rawGet()`
#### `Inputs::rawGet()`

`php://input` -> `$_GET`

```php
public function rawGet(string $key, mixed $default = null, ?array $validation = null): mixed;
```

#### `Input::rawPost()`
#### `Inputs::rawPost()`

`php://input` -> `$_POST`

```php
public function rawPost(string $key, mixed $default = null, ?array $validation = null): mixed;
```

#### `Input::rawGetPost()`
#### `Inputs::rawGetPost()`

`php://input` -> `$_GET` -> `$_POST`

```php
public function rawGetPost(string $key, mixed $default = null, ?array $validation = null): mixed;
```

#### `Input::rawPostGet()`
#### `Inputs::rawPostGet()`

`php://input` -> `$_POST` -> `$_GET`

Expand All @@ -188,23 +188,23 @@ public function rawPostGet(string $key, mixed $default = null, ?array $validatio

Checks to see if the requested entry has been declared.

#### `Input::hasGet()`
#### `Inputs::hasGet()`

It does something like `isset($_GET['key'])` , case-insensitively.

```php
public function hasGet(string $key): bool;
```

#### `Input::hasPost()`
#### `Inputs::hasPost()`

It does something like `isset($_POST['key'])` , case-insensitively.

```php
public function hasPost(string $key): bool;
```

#### `Input::hasRaw()`
#### `Inputs::hasRaw()`

Case-insensitively, it queries the body inputs for a key value.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"minimum-stability": "stable",
"require": {
"php": ">=7.4",
"php": ">=7.2",
"ext-json": "*",
"initphp/parameterbag": "^1.0",
"initphp/validation": "^1.0"
Expand Down
43 changes: 16 additions & 27 deletions src/Input.php → src/Facede/Inputs.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?php
/**
* Input.php
* Inputs.php
*
* This file is part of InitPHP.
* This file is part of Input.
*
* @author Muhammet ŞAFAK <[email protected]>
* @copyright Copyright © 2022 InitPHP
* @license http://initphp.github.io/license.txt MIT
* @version 1.0.2
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 1.1
* @link https://www.muhammetsafak.com.tr
*/

declare(strict_types=1);

namespace InitPHP\Input;
namespace InitPHP\Input\Facede;

/**
* @mixin Stack
* @mixin \InitPHP\Input\Inputs
* @method static mixed get(string $key, mixed $default = null, ?array $validation = null)
* @method static mixed getPost(string $key, mixed $default = null, ?array $validation = null)
* @method static mixed getRaw(string $key, mixed $default = null, ?array $validation = null)
Expand All @@ -36,39 +36,28 @@
* @method static bool hasRaw(string $key)
* @method static bool hasPost(string $key)
*/
final class Input
class Inputs
{

protected static Stack $stack;
/** @var \InitPHP\Input\Inputs */
private static $Inputs;

public function __construct()
private static function getInputInstance(): \InitPHP\Input\Inputs
{
self::getStackInstance();
}

public function __destruct()
{
if(isset(self::$stack)){
self::$stack->__destruct();
if(!isset(self::$Inputs)){
self::$Inputs = new \InitPHP\Input\Inputs();
}
return self::$Inputs;
}

public function __call($name, $arguments)
{
return self::getStackInstance()->{$name}(...$arguments);
return self::getInputInstance()->{$name}(...$arguments);
}

public static function __callStatic($name, $arguments)
{
return self::getStackInstance()->{$name}(...$arguments);
}

protected static function getStackInstance(): Stack
{
if(!isset(self::$stack)){
self::$stack = new Stack();
}
return self::$stack;
return self::getInputInstance()->{$name}(...$arguments);
}

}
Loading

0 comments on commit 8e2abd9

Please sign in to comment.