PHPackages                             codememory/entity-response-control - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. codememory/entity-response-control

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

codememory/entity-response-control
==================================

Controls the response from entities or other objects based on constraints

v5.1.4(8mo ago)1901MITPHPPHP &gt;=8.3

Since Feb 3Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/codememory1/entity-response-control)[ Packagist](https://packagist.org/packages/codememory/entity-response-control)[ RSS](/packages/codememory-entity-response-control/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (4)Versions (26)Used By (1)

Codememory Entity response control
----------------------------------

[](#codememory-entity-response-control)

#### This library is designed for prototyping the returned array, basically you describe the schema of how and what you want to get in the array. As an example: You have a Doctrine entity and you need to give data to this entity in the API. To do this, you can create a prototype in the form of a class, which will then be converted into an array. You may ask how this is different from symfony/serializer, but the difference is that this library actively uses PHP attributes and you can format your data however you want. In addition, this library can easily handle the task when you need to give in one query not only all entities but also other data of each object, which were received by another SQL/DQL query. Below are some examples

[](#this-library-is-designed-for-prototyping-the-returned-array-basically-you-describe-the-schema-of-how-and-what-you-want-to-get-in-the-array-as-an-example-you-have-a-doctrine-entity-and-you-need-to-give-data-to-this-entity-in-the-api-to-do-this-you-can-create-a-prototype-in-the-form-of-a-class-which-will-then-be-converted-into-an-array-you-may-ask-how-this-is-different-from-symfonyserializer-but-the-difference-is-that-this-library-actively-uses-php-attributes-and-you-can-format-your-data-however-you-want-in-addition-this-library-can-easily-handle-the-task-when-you-need-to-give-in-one-query-not-only-all-entities-but-also-other-data-of-each-object-which-were-received-by-another-sqldql-query-below-are-some-examples)

Translated with DeepL.com (free version)

### Install

[](#install)

```
$ composer require codememory/entity-response-control
```

### Manager creation

[](#manager-creation)

```
use Codememory\EntityResponseControl\ResponsePrototypeManager;
use Codememory\Reflection\ReflectorManager;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Codememory\EntityResponseControl\Factory\PrototypeExecutionContextFactory;
use Codememory\EntityResponseControl\Factory\PropertyWrapperFactory;
use Codememory\EntityResponseControl\Factory\PropertyExecutionContextFactory;
use Codememory\EntityResponseControl\Collectors\BaseCollector;
use Codememory\EntityResponseControl\DecoratorRegistrar;
use Codememory\EntityResponseControl\NamingStrategy\SnakeCamelNamingStrategy;

$cache = new FilesystemAdapter('codememory', directory: 'cache');
$reflectorManager = new ReflectorManager($cache);
$decoratorRegistrar = new DecoratorRegistrar();

$manager = new ResponsePrototypeManager(
    $reflectorManager,
    new PrototypeExecutionContextFactory(
        new PropertyWrapperFactory()
    ),
    new PropertyExecutionContextFactory(),
    new BaseCollector(
        $decoratorRegistrar,
        new SnakeCamelNamingStrategy()
    ),
    $decoratorRegistrar
);
```

### A simple Example

[](#a-simple-example)

```
// Entity
class User {
    ....

    public function getName(): string
    {
        return 'Foo';
    }

    public function getSurname(): string
    {
        return 'Bar';
    }
}

// Prototype
class UserPrototype {
    private ?string $name = null; // null - Default value
    private ?string $surname = null; // null - Default value
}

// In order to collect it is necessary to call the collect method
$result = $manager->collect(UserPrototype::class, new User());
```

> \[!\] Note that if you pass collect as an array of objects as the second argument, the array will be multidimensional, otherwise you will get just an associative array

### Use of decorators

[](#use-of-decorators)

```
// Entity
use Codememory\EntityResponseControl\Decorators\Property;

class Order {
    public function __construct(
        private string $name
    ) {}

    public function getName(): string
    {
        return $this->name;
    }
}

class User {
    public function getOrders(): array
    {
        return [
            new Order('Order 1'),
            new Order('Order 2'),
            new Order('Order 3')
        ];
    }

    public function getSurname(): string
    {
        return 'Bar';
    }
}

// Prototype
class OrderPrototype {
    private ?string $name = null;
}

class UserPrototype {
    #[Property\Getter(['getOrders'])] // Explicitly specify the method to use, since we don't have a getCountOrders or isCountOrders method
    #[Property\Length]
    private ?int $countOrders = null;

    #[Property\Nested(OrderPrototype::class)]
    private array $orders = [];
    private ?string $surname = null;
}

$result = $manager->collect(UserPrototype::class, new User());
```

[![result1](./doc/images/result1.png)](./doc/images/result1.png)

#### Let's imagine that we have users, and statistics on users is considered in a separate query and we need to somehow combine all this data in one query

[](#lets-imagine-that-we-have-users-and-statistics-on-users-is-considered-in-a-separate-query-and-we-need-to-somehow-combine-all-this-data-in-one-query)

```
use Codememory\EntityResponseControl\Decorators\Property;

class User {
    public function __construct(
        private string $id,
        private string $name
    ) {}

    public function getId(): string
    {
        return $this->id;
    }

    public function getName(): string
    {
        return $this->name;
    }
}

$users = [
    new User('1', 'User 1'),
    new User('2', 'User 2'),
    new User('3', 'User 3')
];

$metadata = [
    'success_orders' => [
        '1' => 10,
        '2' => 20,
        '3' => 30
    ]
];

class UserPrototype {
    private ?string $id = null;

    // As the first argument it is necessary to pass the name of the getter, in our case the unique value of the user is his identifier
    // The second argument is to pass the key from where to take values from metadata
    #[Property\FromObjectMetadata('getId', 'success_orders')]
    private ?int $countSuccessOrders = null;
}

$result = $manager->collect(UserPrototype::class, $users, metadata: $metadata);
```

[![result2](./doc/images/result2.png)](./doc/images/result2.png)

> You can also pass metadata not directly to the manager, but also use decorators, for example, to pull data using the service

```
use Codememory\EntityResponseControl\Decorators\Property;
use Codememory\EntityResponseControl\Decorators\Prototype;
use Codememory\EntityResponseControl\Interfaces\PrototypeExecutionContextInterface;

class User {
    public function __construct(
        private string $id,
        private string $name
    ) {}

    public function getId(): string
    {
        return $this->id;
    }

    public function getName(): string
    {
        return $this->name;
    }
}

class Service {
    public static function getMetadata(PrototypeExecutionContextInterface $executionContext): void
    {
        $executionContext->setMetadata([
            'success_orders' => [
                '1' => 10,
                '2' => 20,
                '3' => 30
            ]
        ]);
    }
}

$users = [
    new User('1', 'User 1'),
    new User('2', 'User 2'),
    new User('3', 'User 3')
];

#[Prototype\Callback([Service::class, 'getMetadata'])]
class UserPrototype {
    private ?string $id = null;

    #[Property\FromObjectMetadata('getId', 'success_orders')]
    private ?int $countSuccessOrders = null;
}

// The result will be the same as in the last example.
$result = $manager->collect(UserPrototype::class, $users);
```

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance58

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity71

Established project with proven stability

 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 ~40 days

Recently: every ~51 days

Total

25

Last Release

269d ago

Major Versions

v1.x-dev → v2.0-alpha2023-03-21

v2.x-dev → v3.02023-07-17

v3.x-dev → v4.x-dev2024-10-13

v4.x-dev → v5.02025-02-05

PHP version history (2 changes)v1.0PHP &gt;=8.1

v4.x-devPHP &gt;=8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/4f0d8298c7a2a11b533d914c47247df660c778a99fb682320df53be7b42d941a?d=identicon)[codememory1](/maintainers/codememory1)

---

Top Contributors

[![codememory1](https://avatars.githubusercontent.com/u/67295802?v=4)](https://github.com/codememory1 "codememory1 (88 commits)")

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/codememory-entity-response-control/health.svg)

```
[![Health](https://phpackages.com/badges/codememory-entity-response-control/health.svg)](https://phpackages.com/packages/codememory-entity-response-control)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[flow-php/etl

PHP ETL - Extract Transform Load - Abstraction

378604.0k104](/packages/flow-php-etl)[shlinkio/shlink

A self-hosted and PHP-based URL shortener application with CLI and REST interfaces

5.1k5.2k](/packages/shlinkio-shlink)[api-platform/metadata

API Resource-oriented metadata attributes and factories

275.0M219](/packages/api-platform-metadata)[symfony/ai-bundle

Integration bundle for Symfony AI components

32642.2k24](/packages/symfony-ai-bundle)

PHPackages © 2026

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