bupy7/php-input-filter

A simple and powerful input filter for any PHP applications

2.0.2 2023-12-30 16:36 UTC

This package is auto-updated.

Last update: 2024-10-30 01:37:15 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 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.

License

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