bupy7/php-input-filter

适用于任何PHP应用的简单而强大的输入过滤器

2.0.2 2023-12-30 16:36 UTC

This package is auto-updated.

Last update: 2024-08-30 01:09:11 UTC


README

Stable Version Build status Coverage Status Total Downloads License

适用于任何PHP应用的简单而强大的输入过滤器。它类似于表单,但又不尽相同。 ;)

支持PHP从7.4到8.x版本。

安装

安装此扩展的首选方式是通过composer

$ composer require bupy7/php-input-filter

或添加

"bupy7/php-input-filter": "*"

到您的composer.json文件的require部分。

用法

表单

// 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,
            ],
        ];
    }
}

动作

// 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

测试

运行测试

$ ./vendor/bin/phpunit --no-coverage

运行带覆盖率的测试

$ XDEBUG_MODE=coverage ./vendor/bin/phpunit

HTML覆盖率路径:build/coverage/index.html

链接

php-input-filter基于laminas/laminas-inputfilterlaminas/laminas-validatorlaminas/laminas-filter

许可证

php-input-filter根据BSD-3-Clause许可证发布。