Download the PHP package chamber-orchestra/form-bundle without Composer
On this page you can find all versions of the php package chamber-orchestra/form-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download chamber-orchestra/form-bundle
More information about chamber-orchestra/form-bundle
Files in chamber-orchestra/form-bundle
Package form-bundle
Short Description Symfony 8 bundle for JSON-first API form handling with controller traits, data transformers, Doctrine validation, and RFC 9457 problem details error responses
License MIT
Homepage https://github.com/chamber-orchestra/form-bundle
Informations about the package form-bundle
ChamberOrchestra Form Bundle
A Symfony 8 bundle that simplifies JSON-first form handling for REST APIs. It provides controller traits for the submit/validate/response flow, specialized API form types with CSRF disabled, reusable data transformers, Doctrine-backed uniqueness validation, and structured error responses following RFC 9457 (Problem Details for HTTP APIs).
Features
- Controller traits (
FormTrait,ApiFormTrait) for submit/validate/response flow with null-safe request handling - JSON payload handling for mutation requests with automatic merging of uploaded files
- API form base types (
QueryForm,MutationForm) with CSRF disabled and empty block prefixes for clean JSON payloads - Custom form types:
BooleanType,TimestampType,HiddenEntityTypewith secure query builder parameterization - Data transformers for booleans, Unix timestamps, comma-separated arrays, and JSON strings
- RFC 9457 problem details via
ValidationFailedViewwith structured violations for consistent API error responses - Translatable error normalizer (
ProblemNormalizer) for localized exception messages in problem detail responses UniqueFieldvalidation constraint for Doctrine repositories with multi-field checks, closure-based exclusions, and custom normalizersTelExtensionto strip non-digit characters from phone number inputCollectionUtilsfor syncing Doctrine collections (add new / remove stale items)
Requirements
- PHP ^8.5
- Symfony 8.0 components (framework-bundle, form, validator, config, dependency-injection, runtime, translation, clock)
- Doctrine ORM 3.6
- chamber-orchestra/view-bundle 8.0
Installation
Enable the bundle in config/bundles.php:
Usage
Controller Traits
Use FormTrait for standard HTML form submissions and ApiFormTrait for JSON API endpoints.
handleFormCall() accepts a form class or instance, handles the request, and returns a view or response. handleApiCall() does the same for API endpoints -- it automatically parses JSON payloads for MutationForm types and merges uploaded files.
onFormSubmitted() checks validity, returns a ValidationFailedView on failure, or invokes the callback on success:
API Form Types
Extend QueryForm for GET requests or MutationForm for POST/PUT/PATCH requests. Both disable CSRF protection and use empty block prefixes for clean JSON input/output.
Data Transformers
| Transformer | Description |
|---|---|
TextToBoolTransformer |
Converts "true", "1", "yes" to boolean |
DateTimeToNumberTransformer |
Converts Unix timestamps to DateTimeInterface objects |
ArrayToStringTransformer |
Converts arrays to/from comma-separated strings |
JsonStringToArrayTransformer |
Parses JSON strings to arrays (handles empty strings) |
HiddenEntityType
Loads Doctrine entities by ID from a hidden form field. Supports a custom query_builder option with secure parameterized queries.
UniqueField Validator
Validates field uniqueness against Doctrine repositories. Supports multiple fields, closure-based exclusions, custom normalizers, and targeted error paths.
ProblemNormalizer
Extends Symfony's ProblemNormalizer to translate exception messages when the exception implements TranslatableExceptionInterface. This ensures localized error messages in RFC 9457 problem detail responses.
Response Views
| View | HTTP Status | Description |
|---|---|---|
SuccessView |
200 | Empty success response |
ValidationFailedView |
422 | Form validation errors with structured ViolationView items |
FailureView |
Configurable | Generic error response |
RedirectView |
301/302 | Redirect response for AJAX requests |
SuccessHtmlView |
200 | HTML fragment response for AJAX requests |
Testing
Install dependencies and run the full test suite:
The integration test kernel (tests/Integrational/TestKernel.php) boots a minimal Symfony application with in-memory SQLite for Doctrine tests.
License
MIT
All versions of form-bundle with dependencies
chamber-orchestra/view-bundle Version 8.2.*
symfony/dependency-injection Version 8.2.*
symfony/config Version 8.2.*
symfony/framework-bundle Version 8.2.*
symfony/runtime Version 8.2.*
symfony/form Version 8.2.*
symfony/validator Version 8.2.*
symfony/translation Version 8.2.*
symfony/clock Version 8.2.*
doctrine/orm Version 3.8.*