PHPackages                             dkorzhenkov/model-with-preset-data - 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. dkorzhenkov/model-with-preset-data

ActiveLibrary

dkorzhenkov/model-with-preset-data
==================================

v3.0.0(10mo ago)2244↓100%PHP ^7.2 || ^8.0

Since May 11Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/dkorzhenkov/model-with-preset-data)[ Packagist](https://packagist.org/packages/dkorzhenkov/model-with-preset-data)[ RSS](/packages/dkorzhenkov-model-with-preset-data/feed)WikiDiscussions 3.0 Synced today

READMEChangelog (3)Dependencies (3)Versions (5)Used By (0)

Model with forced validation
============================

[](#model-with-forced-validation)

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

[](#installation)

```
composer require dkorzhenkov/model-with-preset-data
```

Usage
-----

[](#usage)

```
use DKorzhenkov\ModelWithPresetData\AbstractModelWithPresetData;
use DKorzhenkov\ModelWithPresetData\Traits\ToArrayExceptNullWithJsonSerializeTrait;
use Symfony\Component\Validator\Constraints as Assert;

class Message extends AbstractModelWithPresetData implements \JsonSerializable
{
    use ToArrayExceptNullWithJsonSerializeTrait;

    protected string $chatUuid;
    protected string $text;

    protected function getRules(array $data): Assert\Collection
    {
        return new Assert\Collection([
            'fields' => [
                'chatUuid' => [
                    new Assert\Type(['type' => 'string']),
                    new Assert\NotBlank(),
                    new Assert\Uuid(),
                ],
                'text' => [
                    new Assert\Type(['type' => 'string']),
                    new Assert\NotBlank(),
                ],
            ],
        ]);
    }
}

$apiClient->pushMessage(new Message([
    'chatUuid' => 'fa100d98-c260-4787-80b5-14c561034288',
    'text' => 'test',
]));
```

Error handling
--------------

[](#error-handling)

```
use DKorzhenkov\ModelWithPresetData\Exception\InvalidDataException;

try {
    $message = new Message([
        'chatUuid' => 'invalid uuid',
        'text' => 'test',
    ]);
} catch (InvalidDataException $exception) {
    $exception->getViolationList();
    // ...
}
```

Casts
-----

[](#casts)

```
class MessageInfo extends AbstractModelWithPresetData
{
    protected Chat $chat;
    protected string $text;

    protected function getCasts(): array
    {
        return [
            'chat' => new ArrayToModelCast(Chat::class, false),
        ];
    }

    protected function getRules(array $data): Assert\Collection
    {
        return new Assert\Collection([
            'fields' => [
                'chat' => [
                    new Assert\NotNull(),
                    new Assert\Type(['type' => Chat::class]),
                ],
                'text' => [
                    new Assert\Type(['type' => 'string']),
                    new Assert\NotBlank(),
                ],
            ],
        ]);
    }

    public function getChat(): Chat
    {
        return $this->chat;
    }
}

class Chat extends AbstractModelWithPresetData
{
    protected string $uuid;

    protected function getRules(array $data): Assert\Collection
    {
        return new Assert\Collection([
            'fields' => [
                'uuid' => [
                    new Assert\Type(['type' => 'string']),
                    new Assert\NotBlank(),
                    new Assert\Uuid(),
                ],
            ],
        ]);
    }

    public function getUuid()
    {
        return $this->uuid;
    }
}

function handleApiResponse($response): MessageInfo
{
    /**
    * Response:
    * [
    *     'chat' => [
    *         'uuid' => 'fa100d98-c260-4787-80b5-14c561034288'
    *     ],
    *     'text' => 'test',
    * ]
    */
    return new MessageInfo($response->all());
}

$messageInfo = handleApiResponse($response);
$messageInfo->getChat()->getUuid();
```

###  Health Score

33

—

LowBetter than 76% of packages

Maintenance55

Moderate activity, may be stable

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

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

Total

5

Last Release

300d ago

Major Versions

v2.2.0 → v3.0.0-BETA12025-05-26

### Community

Maintainers

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

---

Top Contributors

[![dkorzhenkov](https://avatars.githubusercontent.com/u/210502081?v=4)](https://github.com/dkorzhenkov "dkorzhenkov (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dkorzhenkov-model-with-preset-data/health.svg)

```
[![Health](https://phpackages.com/badges/dkorzhenkov-model-with-preset-data/health.svg)](https://phpackages.com/packages/dkorzhenkov-model-with-preset-data)
```

###  Alternatives

[ezsystems/ezplatform-admin-ui

eZ Platform Admin v2

54802.5k56](/packages/ezsystems-ezplatform-admin-ui)[gointegro/hateoas

GOintegro HATEOAS Lib

418.0k1](/packages/gointegro-hateoas)

PHPackages © 2026

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