assoconnect/doctrine-types-bundle
Symfony bundle integrating Symfony Validator with Doctrine custom DBAL types to avoid duplicate validation/mapping code. Includes common value-object types (money/amount, IBAN/BIC, email, phone, country/currency, locale/timezone, IDs) with nullable and non-nullable support.
Pros:
doctrine/dbal or laravel-doctrine bridges. This avoids reinventing custom validation logic for types like IBAN, SpanishNif, or Money.SpanishNifType directly addresses EU/Spain-specific compliance needs, reducing custom validation code for tax identifiers.EmailType, CurrencyType) in a single bundle.Cons:
Illuminate\Validation is not natively supported; requires manual translation of Symfony constraints to Laravel rules or custom validators.laravel-doctrine/orm) adds complexity for teams unfamiliar with Doctrine’s entity mapping.SpanishNifType) may encourage similar custom types, increasing maintenance overhead if not managed centrally.DBAL Integration:
VARCHAR → SpanishNifType) using Doctrine’s Platform configuration.// config/doctrine.php
'dbal' => [
'types' => [
'spanish_nif' => \AssoConnect\DoctrineTypesBundle\DBAL\Types\SpanishNifType::class,
],
];
ORM Integration:
laravel-doctrine/orm or manual @Type annotations in entities.use Doctrine\ORM\Mapping as ORM;
use AssoConnect\DoctrineTypesBundle\DBAL\Types\SpanishNifType;
#[ORM\Entity]
class Client {
#[ORM\Column(type: SpanishNifType::NAME)]
private string $taxId;
}
Validation Integration:
Validator or custom rules.// Replace Symfony constraint with Laravel rule
use Illuminate\Validation\Rule;
$validator->addRules([
'tax_id' => ['required', Rule::custom(function ($attribute, $value) {
return (new SpanishNifType())->convertToDatabaseValue($value) !== null;
})],
]);
High:
SpanishNifType) may need additional business logic (e.g., locale-aware rules).Medium:
EXPLAIN ANALYZE).Low:
SpanishNifType is a low-risk addition (similar to existing types like IBAN or Siret).Validator extensions? What’s the effort estimate?SpanishNifType cover all edge cases (e.g., historical formats, validation rules)? Are similar types needed for other locales (e.g., ItalianCodiceFiscale)?| Laravel Component | Bundle Integration | Compatibility Notes |
|---|---|---|
| Eloquent ORM | ❌ Not directly supported | Use Doctrine ORM via laravel-doctrine/orm or avoid for pure Eloquent projects. |
| Doctrine DBAL | ✅ Full support | Replace column types in migrations (e.g., SpanishNifType for tax IDs). |
| Laravel Validation | ⚠️ Manual translation required | Symfony constraints must be adapted to Validator::extend() or custom rules. |
| Laravel Migrations | ✅ Direct usage | Use doctrine/dbal migrations with custom type configurations. |
| Laravel Repositories | ✅ DBAL-compatible | Ideal for repositories using raw queries or Doctrine repositories. |
| PHP 8.4+ | ✅ Required | Aligns with Laravel 10+; manual patches needed for Laravel 9.x. |
| Composer Dependencies | doctrine/dbal, assoconnect/doctrine-types-bundle |
Adds ~5MB to vendor size; minimal runtime overhead. |
Phase 1: DBAL Integration (Low Risk)
composer require doctrine/dbal assoconnect/doctrine-types-bundle
config/doctrine.php:
'types' => [
'spanish_nif' => \AssoConnect\DoctrineTypesBundle\DBAL\Types\SpanishNifType::class,
'iban' => \AssoConnect\DoctrineTypesBundle\DBAL\Types\IbanType::class,
],
$table->column('tax_id', 'spanish_nif')->nullable();
Validator with custom rules (see below).Phase 2: ORM Integration (Medium Risk)
laravel-doctrine/orm:
composer require laravel-doctrine/orm
config/doctrine.php.#[ORM\Column(type: SpanishNifType::NAME)]
private string $taxId;
Phase 3: Validation Layer (High Risk)
How can I help you explore Laravel packages today?