adamsafr/form-request-bundle
Symfony bundle bringing Laravel-style Form Requests: create custom request classes with validation rules that run before controller actions. Simple install via Composer/Flex, optional JSON error listeners for access denied, validation and JSON decode failures.
FormRequest pattern in Symfony, which is a highly opinionated change for teams accustomed to Symfony’s native request handling (e.g., Request objects, Validator component). This introduces abstraction debt if the team later migrates back to Laravel or adopts alternative validation strategies (e.g., API Platform’s ValidationGroups).ValidatorInterface) or event listeners may offer more flexibility for complex workflows.Validator component under the hood, ensuring consistency with existing validation constraints (e.g., @Assert\*). Risk of duplication if the project already uses Symfony’s native validation heavily.FormRequest classes, which may break existing request handling (e.g., manual Request object access). Mitigation: Use decorators or middlewares to bridge gaps.FormRequest instead of Request), but integration tests may need updates to account for the new validation layer.Attribute validation).symfony/validator).FormRequest adds a pre-validation step, which may introduce latency in high-throughput APIs. Benchmark against Symfony’s native Validator + ConstraintValidator.FormRequest classes may lag).Validator may handle these better.Validator + ParamConverter or API Platform’s ValidationGroups achieve the same goals with less risk?$request->validate()) over Symfony’s annotation-based approach?Validator, but risks duplicating validation logic if both are used.Validator usage with FormRequest classes.FormRequest mocks.FormRequest behavior.nelmio/api-doc-bundle). Use composer why-not to detect conflicts.Default, Create, Update) may interact with Doctrine’s lifecycle callbacks.| Phase | Task | Tools/Metrics |
|---|---|---|
| Assessment | Audit existing validation logic for FormRequest suitability. |
Static analysis (PHPStan), test coverage |
| Setup | Install bundle, configure AppKernel.php, update composer.json. |
composer require, CI checks |
| Pilot | Refactor 1–2 controllers to use FormRequest. |
Performance benchmarks, error logs |
| Validation | Ensure all edge cases (e.g., nested objects, custom constraints). | Test suites, manual QA |
| Rollout | Gradually replace controllers; deprecate old validation patterns. | Feature flags, monitoring |
| Optimization | Cache FormRequest validation results (if applicable). |
OPcache, Symfony’s Validator cache |
symfony/validator for breaking changes.FormRequest-like features (e.g., Attribute validation).FormRequest classes stay in sync with database schema changes (e.g., new required fields).FormRequest validation errors may obscure Symfony’s native error formatting. Use ValidatorInterface to access raw errors.FormRequest classes (e.g., as generic objects).FormRequest classes.->rules() vs. @Assert\*).FormRequest adds ~1–5ms per request (benchmark with blackfire.io). Mitigate with:
memory_get_usage()).FormRequest is stateless, so it scales horizontally like Symfony’s native validation.RateLimiter to prevent validation spam (e.g., brute-force attacks).| Failure Scenario | Impact | Mitigation Strategy |
|---|---|---|
| Bundle incompatibility | Broken validation, 500 errors | Fallback to native Validator, feature flags |
| Validation logic errors | Rejected valid requests | Pre-deploy validation tests, canary releases |
| Symfony version mismatch | Bundle crashes | Pin symfony/* versions in composer.json |
| Custom constraint failures | Silent validation bypass | Log raw validator errors, add health checks |
| IDE/tooling misconfiguration | Developer productivity loss | Custom PhpStorm plugins, VSCode snippets |
Validator + FormRequest.How can I help you explore Laravel packages today?