Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Extra Validator Bundle Laravel Package

devilcius/extra-validator-bundle

Symfony bundle adding extra validators for common Spanish form fields. Includes CCC (Código Cuenta Cliente) bank account validation and NIF/DNI fiscal ID validation. Install via Composer and configure constraints in validation.xml for your entity properties.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Niche but Critical: The package addresses a highly specific but business-critical need for Spanish financial/legal validation (CCC, DNI/NIF). It aligns perfectly with products targeting Spain or requiring compliance with Spanish regulatory formats (e.g., banking, tax, or government services).
  • Validation-Centric Design: The bundle’s constraint-based approach is a natural fit for Symfony’s validation ecosystem. For Laravel, this translates to a clean integration with its Validator facade or custom rule system, assuming the logic is abstracted properly.
  • Decoupled Logic: The validators are stateless and self-contained, reducing coupling with other system components. This makes them easy to adapt or replace if needed.

Integration Feasibility

  • Symfony: Seamless integration via validation.xml and constraint annotations. Minimal boilerplate required for basic usage.
  • Laravel: Feasible but requires manual adaptation. The core validation logic (regex, checksums) can be extracted and ported to Laravel’s Validator::extend() or custom Rule classes. The effort is justified if Spanish validation is a priority.
  • Dependency Overhead: Minimal external dependencies (only Symfony’s Validator component in its native form). Laravel’s built-in validator service can replicate this functionality without additional libraries.
  • Extensibility: The bundle’s design allows for easy extension (e.g., adding new validators like NIE or CIF) if future requirements arise.

Technical Risk

  • Maintenance Risk: The package’s lack of stars, dependents, or recent activity raises concerns about long-term viability. Risk mitigation includes:
    • Forking the repository to maintain control over the logic.
    • Extracting the validation rules into a standalone Laravel package for broader reuse.
  • Laravel-Specific Challenges:
    • Symfony’s Constraint system does not natively exist in Laravel, requiring custom rule implementations.
    • Error message handling differs between the two frameworks (Symfony’s message options vs. Laravel’s language files).
  • Edge Cases: Spanish validation rules (e.g., CCC bank code formats, DNI letter calculations) may have undocumented nuances or historical formats that the bundle does not cover. Thorough testing with real-world data is essential.
  • Localization: The bundle’s error messages are hardcoded in Spanish. Laravel’s localization system would need to override these messages for multilingual support.

Key Questions

  1. Is Spanish validation a core or optional feature?
    • If core, proceed with integration; if optional, consider whether the effort outweighs the benefits.
  2. What is the fallback plan if the bundle is abandoned?
    • Will the team maintain a fork, rewrite the logic, or use an alternative package?
  3. Are there existing Laravel packages for Spanish validation?
    • Avoid reinventing the wheel; alternatives like spatie/laravel-validation-extensions or custom rules may suffice.
  4. How will validation errors be localized for non-Spanish users?
    • Plan for overriding error messages in Laravel’s language files or customizing the bundle’s output.
  5. Does the bundle support all required Spanish validation formats?
    • Verify coverage for CCC (corporate bank accounts), DNI, NIE, and other identifiers (e.g., CIF for companies).
  6. What are the performance implications of the validators?
    • The logic is likely lightweight, but benchmark if used in high-throughput scenarios (e.g., bulk API validation).

Integration Approach

Stack Fit

  • Symfony: Native compatibility. The bundle integrates directly with Symfony’s validation system via validation.xml and constraint annotations. Ideal for existing Symfony applications or hybrid Laravel/Symfony projects.
  • Laravel: Partial compatibility. The core validation logic can be adapted to Laravel’s Validator facade or custom Rule classes. Key considerations:
    • Validator Extension: Use Validator::extend() to register custom rules (e.g., ccc, dni) with the same logic as the bundle.
    • Custom Rule Objects: Create classes extending \Illuminate\Validation\Rule for type safety and reusability.
    • Form Requests: Integrate the rules into FormRequest validation arrays or annotations.
  • Other PHP Frameworks: Not directly applicable, but the logic can be ported to any framework supporting custom validation rules.

Migration Path

  1. Assess Current Validation System:
    • Audit existing validation logic in Laravel (e.g., FormRequest classes, Validator facade usage).
    • Identify where CCC/DNI validation is needed (e.g., user registration, payment processing).
  2. Extract Validation Logic:
    • Clone the bundle’s repository or extract the validator classes (CccValidator, DniValidator).
    • Focus on the core logic (regex patterns, checksum calculations) in files like Ccc.php and Dni.php.
  3. Port to Laravel:
    • Option 1: Validator Extension
      Validator::extend('ccc', function ($attribute, $value, $parameters, $validator) {
          // Implement CCC logic (e.g., regex, bank code checks)
          return preg_match('/^[\d]{20}$/', $value) && /* checksum validation */;
      });
      
    • Option 2: Custom Rule Classes
      namespace App\Rules;
      use Illuminate\Contracts\Validation\Rule;
      
      class CccRule implements Rule {
          public function passes($attribute, $value) {
              // CCC validation logic
              return true;
          }
          public function message() {
              return 'El formato CCC no es válido.';
          }
      }
      
  4. Update Validation Rules:
    • Replace Symfony’s validation.xml with Laravel’s FormRequest validation:
      public function rules()
      {
          return [
              'ccc' => 'required|ccc', // Uses custom rule
              'dni' => 'required|dni',
          ];
      }
      
    • Alternatively, use annotations or inline validation in controllers.
  5. Localization:
    • Override error messages in Laravel’s language files (resources/lang/{locale}/validation.php):
      'custom' => [
          'ccc' => [
              'required' => 'El CCC es obligatorio.',
              'ccc' => 'El formato CCC no es válido.',
          ],
          'dni' => [
              'required' => 'El DNI es obligatorio.',
              'dni' => 'El formato DNI no es válido.',
          ],
      ],
      
  6. Testing:
    • Write unit tests for the custom rules using Laravel’s Validator facade.
    • Test edge cases (e.g., invalid CCC formats, DNI letter calculations, historical formats).

Compatibility

  • Symfony: 100% compatible with zero changes required.
  • Laravel: ~70–80% compatible with manual adaptation. Key differences:
    • Constraint System: Laravel lacks Symfony’s Constraint annotations, requiring custom rules.
    • Error Handling: Laravel’s language files replace Symfony’s message options in constraints.
    • Dependency Injection: Laravel’s service container differs from Symfony’s, but this does not impact stateless validators.
  • PHP Version: Ensure compatibility with Laravel’s supported PHP version (e.g., 8.0+). The bundle likely targets PHP 7.4+, which may require adjustments for newer PHP features.

Sequencing

  1. Phase 1: Research and Planning (1 day)
    • Review the bundle’s source code to understand the validation logic.
    • Decide on the integration approach (validator extension vs. custom rules).
    • Identify all use cases requiring Spanish validation (e.g., user profiles, payments).
  2. Phase 2: Logic Extraction (1–2 days)
    • Extract the CCC and DNI validation logic from the bundle.
    • Adapt the logic to Laravel’s validation system (e.g., Validator::extend() or custom rules).
  3. Phase 3: Integration (2–3 days)
    • Integrate the custom rules into FormRequest classes or API validation pipelines.
    • Update error messages for localization.
  4. Phase 4: Testing (1–2 days)
    • Write unit tests for the custom rules.
    • Test with real-world data (e.g., valid/invalid CCC/DNI samples).
    • Verify edge cases (e.g., historical formats, special characters).
  5. Phase 5: Documentation and Deployment (1 day)
    • Document the custom rules and their usage.
    • Deploy to staging/production and monitor for issues.

Operational Impact

Maintenance

  • Symfony: Low maintenance overhead. Updates to the bundle are straightforward, and the constraint-based system is stable.
  • Laravel: Moderate maintenance overhead due to custom rule implementations. Considerations:
    • Forking: If the original bundle is abandoned, maintain a fork or standalone package for the Laravel rules.
    • Logic Abstraction: Encapsulate the validation logic in a service or trait to simplify future updates.
    • Testing: Maintain unit tests for the custom rules to catch regressions.
  • Risk Mitigation:
    • Document the validation logic and its sources (e.g., Spanish tax authority guidelines).
    • Monitor the original bundle for updates or issues, even if not directly using it.

Support

  • Symfony: Limited community support due to the bundle’s niche focus
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony
spatie/flare-daemon-runtime