PHPackages                             chamber-orchestra/view-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. chamber-orchestra/view-bundle

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

chamber-orchestra/view-bundle
=============================

Symfony bundle providing a typed, reusable view layer for building JSON API responses with automatic property binding and cache-warmed serialization

v8.0.23(4mo ago)2263.0k↑14.3%23[5 PRs](https://github.com/chamber-orchestra/view-bundle/pulls)5MITPHPPHP ^8.5CI passing

Since Mar 6Pushed today3 watchersCompare

[ Source](https://github.com/chamber-orchestra/view-bundle)[ Packagist](https://packagist.org/packages/chamber-orchestra/view-bundle)[ Docs](https://github.com/chamber-orchestra/view-bundle)[ RSS](/packages/chamber-orchestra-view-bundle/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (13)Versions (42)Used By (5)

[![PHP Composer](https://github.com/chamber-orchestra/view-bundle/actions/workflows/php.yml/badge.svg)](https://github.com/chamber-orchestra/view-bundle/actions/workflows/php.yml)[![PHPStan](https://camo.githubusercontent.com/745eb989b9e4903dc598fe2cc63ed4226198be55b7c729001cbd1ece7676fef6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6d61782d627269676874677265656e2e737667)](https://phpstan.org/)[![PHP-CS-Fixer](https://camo.githubusercontent.com/6ea88fbe545f6f06950dd97b31be7621fcb0a0056644de2ea36e44b7de33adc4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532307374796c652d5045522d2d435325323025324625323053796d666f6e792d626c75652e737667)](https://cs.symfony.com/)[![Latest Stable Version](https://camo.githubusercontent.com/19b2451a5251901234787173016dee85793320401924856e63384310a1763b44/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6368616d6265722d6f72636865737472612f766965772d62756e646c652e737667)](https://packagist.org/packages/chamber-orchestra/view-bundle)[![Total Downloads](https://camo.githubusercontent.com/572237f23b26db09606549c03be193a19760f1b6d376606a406badbaa2f77eeb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6368616d6265722d6f72636865737472612f766965772d62756e646c652e737667)](https://packagist.org/packages/chamber-orchestra/view-bundle)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP 8.5+](https://camo.githubusercontent.com/2371eeb1a98f81a6894947d4d7b429326ee7f4dbeb3d8940776b4ae7b8442725/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e352532422d3737374242342e737667)](https://www.php.net/)[![Symfony 8.0](https://camo.githubusercontent.com/daaa476b3cc456701380f7d0fbdc3bbe9983e89d3267f99870daa88aa719e181/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d382e302d3030303030302e737667)](https://symfony.com/)

ChamberOrchestra View Bundle
============================

[](#chamberorchestra-view-bundle)

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
------------

[](#key-features)

- **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
------------

[](#requirements)

- PHP 8.5+
- Symfony 8.0 components (http-kernel, serializer, property-access, dependency-injection, config, framework-bundle)
- doctrine/common ^3.5

Installation
------------

[](#installation)

```
composer require chamber-orchestra/view-bundle:8.0.*
```

Enable the bundle in `config/bundles.php`:

```
return [
    // ...
    ChamberOrchestra\ViewBundle\ChamberOrchestraViewBundle::class => ['all' => true],
];
```

Quick Start
-----------

[](#quick-start)

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

```
use ChamberOrchestra\ViewBundle\Attribute\BindsFrom;
use ChamberOrchestra\ViewBundle\Attribute\Type;
use ChamberOrchestra\ViewBundle\View\BindView;
use ChamberOrchestra\ViewBundle\View\IterableView;

#[BindsFrom(User::class)]
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 the view from a controller — the bundle converts it to a `JsonResponse` automatically:

```
#[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 pass through unchanged.

View Types
----------

[](#view-types)

ViewPurpose`ResponseView`Base response with HTTP status (200) and `Content-Type: application/json` headers`DataView`Wraps any view or array under a `"data"` key`BindView`Maps matching properties from a source object using reflection`IterableView`Maps collections via a callback or view class string`KeyValueView`Produces associative array output for metadata blocks### BindView Property Binding

[](#bindview-property-binding)

`BindView` uses `BindUtils` to synchronize properties between source objects and view instances. It handles:

- Built-in PHP types and custom objects
- `ViewInterface` subclasses (auto-constructed)
- `IterableView` properties with `#[Type(ViewClass::class)]` attribute for typed collections
- Skips union types and incompatible type pairs

Architecture
------------

[](#architecture)

### Request/Response Flow

[](#requestresponse-flow)

1. **SetVersionSubscriber** (priority 256) — injects the DI-managed `BindUtils` instance into `BindView` via `BindView::setBindUtils()`
2. Controller returns a `ViewInterface` object
3. **ViewSubscriber** — detects `ViewInterface` results, wraps non-`ResponseViewInterface` in `DataView`, serializes to JSON via `ViewNormalizer`

### View Auto-Discovery

[](#view-auto-discovery)

Views implementing `ViewInterface` are automatically tagged with `chamber_orchestra.view` via `#[AutoconfigureTag]`. The `ViewPass` compiler pass collects these classes and passes them to cache warmers for pre-computation.

Performance Optimizations
-------------------------

[](#performance-optimizations)

The bundle includes a two-phase optimization strategy for production environments:

### Phase 1: Runtime Metadata Caching

[](#phase-1-runtime-metadata-caching)

- `ViewMetadataFactory` caches property metadata in memory
- Direct property access eliminates repeated reflection calls
- 30-50% faster normalization on repeated calls

### Phase 2: Build-Time Cache Warming

[](#phase-2-build-time-cache-warming)

- `ViewMetadataCacheWarmer` pre-computes view property metadata at build time
- `BindUtilsCacheWarmer` pre-computes property mappings (uses `#[BindsFrom]` for targeted source classes, falls back to N² pairs)
- Generated opcache-optimized PHP files stored in `kernel.share_dir`
- Cache files are versioned with `container.build_id` for safe deployments
- 60-80% reduction in reflection overhead on production requests
- Automatic fallback to reflection when warmed cache is unavailable

### Cache Configuration

[](#cache-configuration)

`BindUtils` is registered as a DI service with `$buildId`, `$debug`, and `$shareDir` constructor arguments. When `APP_DEBUG=false`, property accessor caching is enabled with a 24-hour lifetime. `SetVersionSubscriber` injects the configured instance into `BindView` on each request.

**Warm the cache in production:**

```
bin/console cache:warmup --env=prod
```

This generates build-versioned files in the shared cache directory:

- View property metadata (nullability, defaults, types)
- View-to-view property mappings for `BindUtils`

Benchmarks
----------

[](#benchmarks)

PHPBench benchmarks are included to measure serialization performance and cache impact:

```
composer bench                               # Run all benchmarks
vendor/bin/phpbench run --report=default     # Run with default report
```

Benchmark classes: `BindUtilsBench`, `CacheWarmupBench`, `NormalizationBench`.

Development
-----------

[](#development)

```
composer install          # Install dependencies
composer test             # Run all tests (93 tests, 328 assertions)
./bin/phpunit             # Run tests directly
./bin/phpunit --filter X  # Run specific test class or method
```

License
-------

[](#license)

MIT

###  Health Score

60

—

FairBetter than 98% of packages

Maintenance90

Actively maintained with recent releases

Popularity41

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 94.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~24 days

Recently: every ~1 days

Total

31

Last Release

129d ago

Major Versions

7.3.x-dev → v8.0.12025-12-29

PHP version history (3 changes)v7.0.1PHP ^8.3

v7.2.0PHP ^8.4

v8.0.10PHP ^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/44037eb1c8dc2c4fa9871ac213653f33e22a9348dcec7132df07cc71933f2a2e?d=identicon)[wtorsi](/maintainers/wtorsi)

---

Top Contributors

[![wtorsi](https://avatars.githubusercontent.com/u/2115840?v=4)](https://github.com/wtorsi "wtorsi (36 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

doctrinejsonjson-apiphpphp8property-bindingrest-apiserializationsymfonysymfony-bundleview-modeljsonsymfonyserializationviewREST APIJSON-APISymfony Bundleview-modelapi-responseproperty-binding

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/chamber-orchestra-view-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/chamber-orchestra-view-bundle/health.svg)](https://phpackages.com/packages/chamber-orchestra-view-bundle)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1616.4k14](/packages/2lenet-crudit-bundle)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M577](/packages/shopware-core)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9421.6k61](/packages/open-dxp-opendxp)[chameleon-system/chameleon-base

The Chameleon System core.

1028.6k5](/packages/chameleon-system-chameleon-base)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
