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(11mo ago)2244↓100%PHP ^7.2 || ^8.0

Since May 11Pushed 11mo 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 1mo ago

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 74% of packages

Maintenance54

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

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

[sylius/sylius

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

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

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k48.1M235](/packages/api-platform-core)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k16.7M309](/packages/easycorp-easyadmin-bundle)[phpro/soap-client

A general purpose SoapClient library

8885.6M46](/packages/phpro-soap-client)[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.3M152](/packages/sulu-sulu)

PHPackages © 2026

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