PHPackages                             gryfoss/mvc-vm-normalizer - 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. [Templating &amp; Views](/categories/templating)
4. /
5. gryfoss/mvc-vm-normalizer

ActiveLibrary[Templating &amp; Views](/categories/templating)

gryfoss/mvc-vm-normalizer
=========================

Symfony MVC View Model Normalizer - provides DefaultViewModel attribute and normalizer for intermediate layer between data models and view serialization

v2.0.0(7mo ago)0359MITPHPCI passing

Since Aug 18Pushed 7mo agoCompare

[ Source](https://github.com/GryfOSS/mvc-vm-normalizer)[ Packagist](https://packagist.org/packages/gryfoss/mvc-vm-normalizer)[ RSS](/packages/gryfoss-mvc-vm-normalizer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (9)Versions (6)Used By (0)

MVC View Model Normalizer
=========================

[](#mvc-view-model-normalizer)

[![Tests](https://github.com/gryfoss/mvc-vm-normalizer/actions/workflows/tests.yml/badge.svg)](https://github.com/gryfoss/mvc-vm-normalizer/actions/workflows/tests.yml/badge.svg)[![Coverage](https://camo.githubusercontent.com/32855e94577df9d0a30995653b17d33a5fbfdf644518f96ea0374313397d19b7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e)](https://camo.githubusercontent.com/32855e94577df9d0a30995653b17d33a5fbfdf644518f96ea0374313397d19b7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e)[![PHP](https://camo.githubusercontent.com/f41026a5995de258d5b2b2a23a549bf8e737f5d440af75acdfe7c3a996cc58d3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e32253230253743253230382e332d626c7565)](https://camo.githubusercontent.com/f41026a5995de258d5b2b2a23a549bf8e737f5d440af75acdfe7c3a996cc58d3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e32253230253743253230382e332d626c7565)[![Tests](https://camo.githubusercontent.com/3d458d74c330a553eb1ccdcb0629642c5318ff26df5aaa2f535f51035134eec2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d504850556e697425323025324225323042656861742d626c7565)](https://camo.githubusercontent.com/3d458d74c330a553eb1ccdcb0629642c5318ff26df5aaa2f535f51035134eec2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d504850556e697425323025324225323042656861742d626c7565)

This adds the `DefaultViewModel` attribute into the system and a Symfony Serializer normalizer that automatically transforms entities into their designated ViewModels during serialization.

✨ Features
----------

[](#-features)

- **Attribute-based Configuration**: Use `#[DefaultViewModel]` to specify ViewModels
- **SerializedName Support**: Full support for `#[SerializedName('alias')]` attributes
- **Nested Object Handling**: Automatic handling of nested ViewModels
- **Collection Support**: Transform arrays/collections of objects
- **100% Test Coverage**: Comprehensive PHPUnit + Behat test coverage
- **CI/CD Ready**: Complete GitHub Actions workflows

🚀 Quick Start
-------------

[](#-quick-start)

### Installation

[](#installation)

```
composer require gryfoss/mvc-vm-normalizer
```

### Configuration

[](#configuration)

Configure the normalizer in your `services.yaml`:

```
  GryfOSS\Mvc\Normalizer\DefaultViewModelNormalizer:
    tags:
      - { name: serializer.normalizer, priority: 100 }
```

### Basic Usage

[](#basic-usage)

1. Add the attribute to your entities:

```
#[DefaultViewModel(viewModelClass: UserViewModel::class)]
class User implements NormalizableInterface
{
    public function __construct(
        private string $firstName,
        private string $lastName,
        private int $age
    ) {}

    // getters...
}
```

2. Create your ViewModel:

```
class UserViewModel implements ViewModelInterface
{
    public function __construct(private User $user) {}

    #[SerializedName('n')]
    public function getName(): string
    {
        return $this->user->getFirstName() . ' ' . $this->user->getLastName();
    }

    #[SerializedName('a')]
    public function getAge(): int
    {
        return $this->user->getAge();
    }
}
```

**Result:**

```
{
  "n": "John Doe",
  "a": 30
}
```

🧪 Testing
---------

[](#-testing)

### Run All Tests

[](#run-all-tests)

```
./bin/run-ci-tests.sh
```

### Individual Test Suites

[](#individual-test-suites)

```
# PHPUnit tests with coverage
XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text

# Behat acceptance tests
./vendor/bin/behat

# Coverage verification
php bin/check-coverage.php
```

📚 Documentation
---------------

[](#-documentation)

- **[Behat Tests](features/README.md)**: Acceptance test documentation
- **[Coverage Reports](coverage/html/)**: Detailed coverage analysis

🤝 Contributing
--------------

[](#-contributing)

1. Fork the repository
2. Create a feature branch
3. Run tests: `./bin/run-ci-tests.sh`
4. Ensure 100% coverage
5. Submit a pull request

📄 License
---------

[](#-license)

This project is licensed under the MIT License.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance69

Regular maintenance activity

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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 ~17 days

Total

4

Last Release

211d ago

Major Versions

v1.0.2 → v2.0.02025-10-09

### Community

Maintainers

![](https://www.gravatar.com/avatar/b76a5fac115d24d698d09cc939a6922bf309732ae61d0f2f215ae9e7397658ea?d=identicon)[ideaconnect](/maintainers/ideaconnect)

---

Top Contributors

[![bpacholek](https://avatars.githubusercontent.com/u/3039162?v=4)](https://github.com/bpacholek "bpacholek (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gryfoss-mvc-vm-normalizer/health.svg)

```
[![Health](https://phpackages.com/badges/gryfoss-mvc-vm-normalizer/health.svg)](https://phpackages.com/packages/gryfoss-mvc-vm-normalizer)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19462.3M1.3k](/packages/drupal-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M151](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)

PHPackages © 2026

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