bupy7 / php-input-filter
A simple and powerful input filter for any PHP applications
2.0.2
2023-12-30 16:36 UTC
Requires
- php: >=7.4
- laminas/laminas-filter: ^2.13
- laminas/laminas-inputfilter: ^2.13
- laminas/laminas-validator: ^2.20
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.45.0
- phpunit/phpunit: ^9.5.28
README
A simple and powerful input filter for any PHP application. It's alike a form, but not the same. ;)
Supporting PHP from 7.4 up to 8.x.
Installation
The preferred way to install this extension is through composer:
$ composer require bupy7/php-input-filter
or add
"bupy7/php-input-filter": "*"
to the require
section of your composer.json file.
Usage
Form:
// module/Application/src/Form/SignInForm.php use Bupy7\InputFilter\FormAbstract; class SignInForm extends FormAbstract { /** * @var string|mixed */ public $email; /** * @var string|mixed */ public $password; protected function inputs(): array { return [ [ 'name' => 'email', 'required' => true, 'validators' => [ [ 'name' => 'EmailAddress', ], ], ], [ 'name' => 'password', 'required' => true, ], ]; } }
Action:
// module/Application/src/Action/AuthAction.php use Application/Form/SignInForm; $signInForm = new SignInForm(); if ($this->getRequest()->isPost()) { $signInForm->setValues($this->getRequest()->getPost()); if ($signInForm->isValid()) { // authentication... // $auth->setLogin($signInForm->email) // $auth->setPassword($signInForm->password); // $result = $auth->authenticate(); if ($result->isValid()) { // some actions } } } // to do something next
Testing
Run tests:
$ ./vendor/bin/phpunit --no-coverage
Run tests with coverage:
$ XDEBUG_MODE=coverage ./vendor/bin/phpunit
HTML coverage path: build/coverage/index.html
Links
The php-input-filter
was based on laminas/laminas-inputfilter
, laminas/laminas-validator
and laminas/laminas-filter
.
- Documentation of
laminas/laminas-inputfilter
; - Documentation of
laminas/laminas-validator
; - Documentation of
laminas/laminas-filter
.
License
php-input-filter
is released under the BSD-3-Clause License.