bupy7/php-input-filter

A simple and powerful input filter for any PHP applications

2.0.3 2024-12-20 20:41 UTC

This package is auto-updated.

Last update: 2024-12-20 21:05:14 UTC


README

Stable Version Build status Coverage Status Total Downloads License

A simple and powerful input filter for any PHP application. It's alike a form, but not the same. ;)

Supporting PHP from 8.0 up to newest.

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.

License

php-input-filter is released under the BSD-3-Clause License.