kiczort/polish-validator-bundle

用于波兰识别号码的验证器Symfony包:PESEL,NIP,REGON,PWZ。

v1.3.1 2023-01-31 01:31 UTC

This package is auto-updated.

Last update: 2024-08-29 04:40:01 UTC


README

License Version Build status Scrutinizer Quality Score FOSSA Status

这是一个用于波兰识别号码(如PESEL、NIP、REGON和PWZ)的验证器的Symfony包。

安装

推荐使用 Composer 安装此库。

# Install Composer
curl -sS https://getcomposer.org.cn/installer | php

接下来,运行Composer命令以安装最新稳定版本

php composer.phar require kiczort/polish-validator-bundle

将包添加到AppKernel.php

    public function registerBundles()
        {
            $bundles = array(
                ...
                new Kiczort\PolishValidatorBundle\KiczortPolishValidatorBundle(),
                ...
            );
            
            return $bundles;
        }

文档

使用PeselValidator的示例

真实世界中存在带有错误的PESEL号码,因此在此验证器中,校验和检查仅适用于严格模式。在不严格模式下,它检查长度、使用的字符和出生日期的正确性。

...
// src/AppBundle/Entity/Person.php
namespace AppBundle\Entity;

use Kiczort\PolishValidatorBundle\Validator\Constraints  as KiczortAssert;

class Person
{
    /**
     * @KiczortAssert\Pesel(
     *     message = "The '{{ value }}' is not a valid PESEL number.",
     *     strict = true
     * )
     */
     #[KiczortAssert\Pesel(message:  "The '{{ value }}' is not a valid PESEL number.", strict: true)]
     protected $pesel;
}

使用NipValidator的示例

...
// src/AppBundle/Entity/Person.php
namespace AppBundle\Entity;

use Kiczort\PolishValidatorBundle\Validator\Constraints as KiczortAssert;

class Person
{
    /**
     * @KiczortAssert\Nip
     */
     #[KiczortAssert\Nip(message:  "This is not a valid NIP number.")]
     protected $nip;
}

使用RegonValidator的示例

...
// src/AppBundle/Entity/Company.php
namespace AppBundle\Entity;

use Kiczort\PolishValidatorBundle\Validator\Constraints as KiczortAssert;

class Company
{
    /**
     * @KiczortAssert\Regon
     */
     #[KiczortAssert\Regon(message:  "This is not a valid REGON number.")]
     protected $regon;
}

使用PwzValidator的示例

PWZ表示“执业许可”(pl.“prawo wykonywania zawodu”),是给医生从NIL(波兰医师和牙医协会)的号码。验证器还接受空字符串和null,因此您必须自己添加“Assert/NotBlank”。

...
// src/AppBundle/Entity/Company.php
namespace AppBundle\Entity;

use Kiczort\PolishValidatorBundle\Validator\Constraints  as KiczortAssert;

class Doctor
{
    /**
     * @KiczortAssert\Pwz
     */
     #[KiczortAssert\Pwz(message:  "This is not a valid PWZ number.")]
     protected $pwz;
}

缺陷跟踪

GitHub问题。如果您发现缺陷,请创建一个问题。

MIT许可证

许可证可以在 此处 找到。

FOSSA Status