GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Respect/ValidationBundle: A Respect\Validation Bundle for Symfony

BranchesTags
Open more actions menu

Latest commit

 

History

40 Commits
40 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
config
config
 
 
src
src
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
phpcs.xml.dist
phpcs.xml.dist
 
 
phpstan.neon.dist
phpstan.neon.dist
 
 
phpunit.xml.dist
phpunit.xml.dist
 
 

Repository files navigation

Respect/ValidationBundle

Symfony bundle for Respect/Validation.

Installation

composer require respect/validation-bundle

Register the bundle in config/bundles.php:

return [
    // ...
    Respect\ValidationBundle\RespectValidationBundle::class => ['all' => true],
];

Usage

Inject Respect\Validation\ValidatorBuilder into any service via constructor injection:

use Respect\Validation\ValidatorBuilder;

final class MyService
{
    public function __construct(private readonly ValidatorBuilder $validator)
    {
    }

    public function process(mixed $value): void
    {
        $this->validator->stringType()->length(1, 100)->check(
            $value,
            new \DomainException('Invalid value.')
        );

        // proceed...
    }
}

ValidatorFactory is also available for autowiring if you need to build validators programmatically.

Custom rule namespaces

Add your own rule namespaces in config/packages/respect_validation.yaml:

respect_validation:
    rule_namespaces:
        - App\Validation\Rules

Rule classes under those namespaces (extending Respect\Validation\Validators\Core\Simple) become available via the builder — e.g. a class App\Validation\Rules\AcmeId can be used as $builder->acmeId()->isValid($value). User namespaces are checked before the built-in Respect\Validation\Validators, so custom rules can shadow defaults.

Container ownership

The bundle replaces Respect\Validation\ContainerRegistry's default container with Symfony's container, so v::email(), ValidatorBuilder::init(), and every other entry point in Respect/Validation resolves through the same container that serves your Symfony services. This happens at two points:

  1. Compile time — a compiler pass calls ContainerRegistry::setContainer() with the ContainerBuilder while the container is being built. Any compiler pass running after this one can call the static API safely.
  2. Runtime — the bundle overrides setContainer() so that the moment the kernel attaches the compiled container to bundles (before any boot() runs and before any service is resolved), the registry switches to the runtime container.

The practical guarantee: in any Symfony application code (controllers, console commands, listeners, service constructors), Respect\Validation\ContainerRegistry points at Symfony's container. There is no window in normal Symfony usage where the static API would resolve against Respect/Validation's default PHP-DI container.

The only situation this does not cover is code that runs Respect/Validation without a Symfony kernel at all — for example, a standalone script that uses v::email() directly. In that scenario there is no bundle to register, and Respect/Validation falls back to its built-in PHP-DI container, which is the expected behaviour outside of Symfony.

License

MIT. See LICENSE.

About

A Respect\Validation Bundle for Symfony

Resources

Readme
BSD-3-Clause license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity
Custom properties

Stars

17 stars

Watchers

8 watching

Forks

3 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.