Download the PHP package fundraisingbox/symfony-precognition without Composer
On this page you can find all versions of the php package fundraisingbox/symfony-precognition. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fundraisingbox/symfony-precognition
More information about fundraisingbox/symfony-precognition
Files in fundraisingbox/symfony-precognition
Package symfony-precognition
Short Description A Symfony bundle that allows validating requests without executing controller code
License MIT
Informations about the package symfony-precognition
Symfony Precognition
A Symfony bundle that validates a request without executing the controller body. A precognitive request runs the normal argument-resolution validation or an explicitly annotated Symfony Form, then short-circuits before the controller runs. This lets a client validate input — for example during live form validation — without creating or mutating anything.
- validation passes →
204 No Content+Precognition-Success: true - validation fails → the application's normal validation error response
- every precognitive response carries
Precognition: trueandVary: Precognition - optional
Precognition-Validate-Only: a,blimits which fields are reported
Routes are opt-in by default. Add #[Precognitive] to a controller method
or class that uses #[MapRequestPayload], #[MapQueryString],
#[MapUploadedFile], or a custom value resolver. Symfony Forms opt in with
#[PrecognitiveForm].
[!IMPORTANT] Precognition only runs validation performed during argument resolution, plus explicitly annotated Symfony Forms. Validation and business rules inside the controller do not run. A
204means that the input is structurally valid, not that the operation would succeed.
Installation
Symfony Flex enables the bundle automatically. Without Flex, add it to
config/bundles.php:
Quick start
Add #[Precognitive] to a route whose arguments are validated:
Send the same request that would be submitted normally, with the
Precognition header:
A valid request receives:
An invalid #[MapRequestPayload] request receives the application's normal
validation response, usually 422, with Precognition: true and
Vary: Precognition headers.
Clients should always check the Precognition: true response header. If a
route has not opted in, the request behaves as if the bundle were absent and
the controller runs normally.
Configuration
Routes must opt in by default. To let every route answer precognitively, enable global mode:
Install symfony/form as well when using #[PrecognitiveForm]:
Documentation
- How precognition works
- Validating request payloads
- Validating query strings
- Validating uploaded files
- Validating Symfony Forms
- Validating selected fields
- Configuring CORS
- Laravel client compatibility
- Vanilla JavaScript frontend example
Prior art
This bundle ports the request/response protocol of Laravel Precognition, also described for Rails by Inertia Precognition. The request and success protocol matches, but validation errors retain Symfony's native status codes and response body.
[!WARNING] The official Laravel Precognition frontend SDKs are not drop-in compatible because they expect Laravel's validation error shape. See the compatibility guide for details and a bridge recipe.
Maintainers & Contribution
Maintained by FundraisingBox Developers. This not an official product by FundraisingBox.
Contributions are welcome - please do not flood with vibe-coded PRs though.
License
MIT. See LICENSE.
All versions of symfony-precognition with dependencies
symfony/config Version ^6.4 || ^7.0 || ^8.0
symfony/dependency-injection Version ^6.4 || ^7.0 || ^8.0
symfony/event-dispatcher Version ^6.4 || ^7.0 || ^8.0
symfony/http-foundation Version ^6.4 || ^7.0 || ^8.0
symfony/http-kernel Version ^6.4 || ^7.0 || ^8.0
symfony/validator Version ^6.4 || ^7.0 || ^8.0