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.
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.
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
Run tests:
$ ./vendor/bin/phpunit --no-coverage
Run tests with coverage:
$ XDEBUG_MODE=coverage ./vendor/bin/phpunit
HTML coverage path: build/coverage/index.html
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
.
php-input-filter
is released under the BSD-3-Clause License.