Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@

# ChamberOrchestra View Bundle

A typed, high-performance Symfony bundle for building reusable JSON API responses. Controllers return plain view objects instead of `Response` — the bundle handles serialization, null stripping, and content negotiation automatically.
A Symfony bundle that provides a **typed view layer for JSON API responses**. Define response shapes as PHP classes, return them from controllers, and let the bundle handle serialization automatically — no manual `JsonResponse` construction needed.

Built for **Symfony 8.0** and **PHP 8.5+**, the bundle eliminates boilerplate in REST API controllers by introducing view models with automatic property binding, collection mapping, and production-ready cache warming.

## Key Features

- **Typed view layer** — define response shapes as PHP classes with typed properties
- **Automatic property binding** — `BindView` maps domain objects to views via reflection
- **Collection mapping** — `IterableView` transforms collections with typed element views
- **Null stripping** — null values are automatically excluded from JSON output
- **Production cache warming** — pre-computed metadata and property mappings eliminate reflection at runtime
- **Build-versioned caching** — cache files are tied to `container.build_id` for safe deployments
- **Typed view models** — define JSON response structures as PHP classes with typed properties
- **Automatic property binding** — `BindView` maps domain object properties to view properties via reflection
- **Collection mapping** — `IterableView` transforms arrays and iterables with typed element views
- **Null stripping** — null values are automatically excluded from serialized JSON output
- **Build-time cache warming** — pre-computed metadata and property mappings eliminate reflection overhead in production
- **Build-versioned caching** — cache files are tied to `container.build_id` for zero-downtime deployments
- **Doctrine proxy support** — transparent lazy-load initialization before property access

## Requirements
Expand All @@ -38,9 +40,9 @@ return [
];
```

## Quickstart
## Quick Start

Create a view that maps fields from a domain object:
Define a view model that maps properties from a domain object:

```php
use ChamberOrchestra\ViewBundle\View\BindView;
Expand All @@ -67,7 +69,7 @@ final class ImageView extends BindView
}
```

Return a view from a controller:
Return the view from a controller — the bundle converts it to a `JsonResponse` automatically:

```php
#[Route('/user/me', methods: ['GET'])]
Expand All @@ -82,7 +84,7 @@ final class GetMeAction

`ViewSubscriber` converts any `ViewInterface` result into a `JsonResponse`. Non-view results pass through unchanged.

## Core Views
## View Types

| View | Purpose |
|------|---------|
Expand Down Expand Up @@ -146,9 +148,9 @@ This generates build-versioned files in the shared cache directory:
- View property metadata (nullability, defaults, types)
- View-to-view property mappings for `BindUtils`

## Benchmarking
## Benchmarks

Benchmark tools are included to measure optimization impact:
Benchmark scripts are included to measure serialization performance and cache impact:

```bash
# Quick normalization timing
Expand Down
19 changes: 14 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{
"name": "chamber-orchestra/view-bundle",
"type": "library",
"description": "The view symfony bundle for JSON API responses",
"type": "symfony-bundle",
"description": "Symfony bundle providing a typed, reusable view layer for building JSON API responses with automatic property binding and cache-warmed serialization",
"keywords": [
"symfony",
"view-bundle",
"symfony-bundle",
"view",
"api",
"json-api",
"api-response",
"serialization",
"property-binding",
"json",
"typescript"
"rest-api",
"view-model"
],
"homepage": "https://github.com/chamber-orchestra/view-bundle",
"license": "MIT",
"authors": [
{
Expand All @@ -19,6 +24,10 @@
"role": "Developer"
}
],
"support": {
"issues": "https://github.com/chamber-orchestra/view-bundle/issues",
"source": "https://github.com/chamber-orchestra/view-bundle"
},
"require": {
"php": "^8.5",
"symfony/http-kernel": "8.0.*",
Expand Down