seferov/request-validator-bundle
seferov/request-validator-bundle is a Symfony bundle for validating incoming HTTP request data with Symfony Validator constraints. Define rules for query or body parameters, reject invalid requests early, and return clear validation errors before controller logic runs.
First, a critical framing note: this is a Symfony bundle, not a Laravel package. Despite the "request validator" name, it hooks into Symfony's kernel.controller event and relies on Doctrine annotations plus Symfony's Validator component. composer require seferov/request-validator-bundle in a Laravel app will install, but nothing will wire it up — there is no service provider, no Kernel, no annotation reader, and no controller event dispatcher to hook into. If you are working in Laravel, the correct "first use case" is to skip this package entirely and use php artisan make:request StoreThingRequest, which is the idiomatic equivalent.
If you are in a Symfony codebase where the bundle is already installed, look first at:
Seferov\RequestValidatorBundle\Configuration\Validator / Validators — the annotation classes you'll be putting on controller methods.kernel.controller — this is where the request params are read and handed to symfony/validator.Resources/config/services.xml — to confirm the validator service and annotation reader wiring match your Symfony version.Minimal usage is roughly: declare the constraints as annotations above an action, then let the bundle pull the named request parameter and validate it before your action body runs.
/**
* @Validators({
* @Validator(name="email", constraints={
* @Assert\NotBlank(),
* @Assert\Email()
* })
* })
*/
public function registerAction(Request $request)
{
// only reached if validation passed
}
For a Laravel developer, the mental model translation is: "annotations on a controller action that behave like a FormRequest that lives in the docblock instead of a class." That should immediately tell you why it's a poor fit for modern Laravel — see the next section for the equivalent patterns you'd actually write.
If you are actually on Symfony (the only supported path):
@Assert\* constraints and custom constraints you've already defined elsewhere in the app, so the bundle piggybacks on your existing validator configuration rather than introducing a parallel ruleset.Laravel equivalents for the same day-to-day needs (recommended):
php artisan make:request, put rules() and authorize() on it, type-hint it in the controller method. This is the direct analogue of an annotated action, but it's testable in isolation, autocompletes in the IDE, and is discoverable via grep.$request->validate([...]) for one-off endpoints. Cheapest option; fine for two or three rules.Rule objects for reusable constraints. php artisan make:rule gives you passes()/message() — the Laravel equivalent of a Symfony ConstraintValidator.Rule::when / Rule::requiredIf. Replaces the Symfony annotation "groups" concept for scenario-based validation.$request->validated() only. Never $request->all() after validation — this is the Laravel habit that most closely mirrors "the controller action only runs on valid input."prepareForValidation() for normalization (trimming, casting empty strings to null) before rules execute — the closest thing to intercepting the raw request params before they hit the validator, which is what the bundle does at the event level.ValidationException renders a 422 JSON response automatically for Accept: application/json — you do not need to build the response plumbing the Symfony bundle leaves to you.Integration tips if you must keep the Symfony bundle: pin the bundle version explicitly ("seferov/request-validator-bundle": "1.x"), keep doctrine/annotations installed and the annotation reader enabled, and write a test around at least one annotated action so a Symfony upgrade that drops annotation support fails loudly rather than silently skipping validation.
composer.json.use statement can result in no validation rather than an error. Add an explicit test that posts invalid data and asserts a 4xx — this is the single most valuable guard you can write.kernel.controller listener priority relative to other listeners (e.g. security, param converters) — check bin/console debug:event-dispatcher kernel.controller.config/bundles.php is not automatic on Flex for abandoned/rare bundles; you may need to add it manually, and the annotation reader must be explicitly configured as a service if you've disabled framework.annotations.kernel.controller listener that reads attributes) is less work than patching the bundle.FormRequest, custom Rule classes, and prepareForValidation(), which give you strictly more capability with first-party support.How can I help you explore Laravel packages today?