chamber-orchestra / form-bundle
The symfony form bundle for JSON API responses
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/chamber-orchestra/form-bundle
Requires
- php: ^8.4
- chamber-orchestra/view-bundle: 8.0.*
- doctrine/orm: 3.6.*
- symfony/clock: 8.0.*
- symfony/config: 8.0.*
- symfony/dependency-injection: 8.0.*
- symfony/form: 8.0.*
- symfony/framework-bundle: 8.0.*
- symfony/runtime: 8.0.*
- symfony/translation: 8.0.*
- symfony/validator: 8.0.*
Requires (Dev)
- phpunit/phpunit: ^12.5
- symfony/test-pack: ^1.2
Conflicts
This package is auto-updated.
Last update: 2025-12-30 21:20:33 UTC
README
A lightweight Symfony bundle for building typed, reusable JSON responses. Views encapsulate serialization concerns so controllers can return simple objects instead of Response.
Requirements
- PHP 8.4
- Symfony 8.0 components (http-kernel, serializer, property-access, dependency-injection, config)
- doctrine/common ^3.5
Installation
composer require chamber-orchestra/view-bundle:8.0.*
Enable the bundle in config/bundles.php:
return [ // ... ChamberOrchestra\ViewBundle\ChamberOrchestraViewBundle::class => ['all' => true], ];
Quickstart
Create a view that maps fields from a domain object:
use ChamberOrchestra\ViewBundle\View\BindView; use ChamberOrchestra\ViewBundle\Attribute\Type; use ChamberOrchestra\ViewBundle\View\IterableView; final class UserView extends BindView { public string $id; public string $name; #[Type(ImageView::class)] public IterableView $images; public function __construct(User $user) { parent::__construct($user); } } final class ImageView extends BindView { public string $path; }
Return a view from a controller:
#[Route('/user/me', methods: ['GET'])] final class GetMeAction { public function __invoke(): UserView { return new UserView($this->getUser()); } }
ViewSubscriber converts any ViewInterface result into a JsonResponse. Non-view results are ignored.
Core Views
ResponseView: base response with status (200) and headers (Content-Type: application/json), overridable in subclasses.DataView: wraps payload underdata.BindView: maps matching properties from a source object to the view; honorsAttribute\TypeonIterableViewproperties for typed collections.IterableView: maps collections via a callback or view class string.KeyValueView: returns an associative array for metadata blocks.
Caching & Build ID
SetVersionSubscriber seeds BindUtils::configure() with container.build_id. When APP_DEBUG=false, property accessor caching is enabled with a 24h lifetime and namespace view_bind.
Development & Tests
- Install deps:
composer install - Run unit/integration tests:
./bin/phpunit - Namespaces live under
ChamberOrchestra\ViewBundle; autoloaded PSR-4 fromsrc/.