Search by

petroslabs / fr-validator-symfony

petroslabs

Symfony Validator constraints for petroslabs/fr-validator (French identifiers: NIR, RIB, SIREN/SIRET, IBAN, BIC, VAT, NAF, phone number)

Package info

github.com/petroslabs/fr-validator-symfony

Type:symfony-bundle

pkg:composer/petroslabs/fr-validator-symfony

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-10-15 17:39 UTC

This package is auto-updated.

Last update: 2026-10-15 18:28:49 UTC


README

CI Mutation testing badge Packagist License

Symfony Validator constraints for petroslabs/fr-validator: NIR, RIB, SIREN, SIRET, IBAN, BIC, VAT number, NAF/APE and phone number, as #[Constraint] attributes.

Why a separate package

The core library has zero framework dependency on purpose — most consumers just want to check a string. This package exists only to translate that into Symfony's Validator component, with its own release cycle and test matrix across supported Symfony versions. If you don't use Symfony, you don't need this package at all.

Installation

composer require petroslabs/fr-validator-symfony

Usage

use PetrosLabs\FrValidatorSymfony\Constraints as Assert;

final class CompanyProfile
{
    #[Assert\Siret]
    public string $siret;

    #[Assert\Iban]
    public string $iban;

    #[Assert\Vat(message: 'This VAT number looks wrong: {{ reason }}')]
    public string $vatNumber;

    #[Assert\Naf(additionalCodes: ['9999Z'])]
    public string $nafCode;
}

Each constraint short-circuits on null/'' (combine with NotBlank if emptiness itself should be rejected), and on failure exposes the core library's typed failure reason — not just a generic "invalid" message — as both the {{ reason }} message parameter and the violation code:

$violations = $validator->validate($companyProfile);

foreach ($violations as $violation) {
    $violation->getCode(); // e.g. "invalid_checksum", "unknown_code"
}

Constraints

Constraint Wraps
Nir NIR (social security number)
Rib RIB key
Siren SIREN
Siret SIRET
Iban French IBAN
Bic BIC/SWIFT (general format)
Vat French VAT number
Naf NAF/APE activity code (accepts additionalCodes, see the core package)
Phone French phone number

Scope and known limitations for each one are documented in the core package's README — this bridge doesn't change or repeat them.

Known v1 simplification

Messages ship with an English default and no pre-built translations — override them like any other Symfony constraint (per-constraint message option, or your app's own translations/validators.*.yaml since no custom translation domain is set). A French-first package not shipping French translations by default is a real gap; it's just not solved yet.

Development

composer install
composer check  # tests + PHPStan (level max) + code style check

See CONTRIBUTING.md.

Security

See SECURITY.md to report a vulnerability.

License

MIT — see LICENSE.