PHPackages                             andreypostal/php-pancake-object - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. andreypostal/php-pancake-object

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

andreypostal/php-pancake-object
===============================

Light and simple helper to work with value objects by providing a serializer and hydrator using PHP Attributes.

v0.0.7(11mo ago)82.1k—8.7%2MITPHPCI passing

Since Mar 21Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/andreypostal/php-pancake-object)[ Packagist](https://packagist.org/packages/andreypostal/php-pancake-object)[ RSS](/packages/andreypostal-php-pancake-object/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (4)Dependencies (1)Versions (8)Used By (2)

🥞 Pancake Object
================

[](#-pancake-object)

[![Coverage Status](https://camo.githubusercontent.com/87846406bef846f79051990a59a034db9930c7b91853c3a099d366976cc1a480/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f616e64726579706f7374616c2f7068702d70616e63616b652d6f626a6563742f62616467652e7376673f6272616e63683d6d61696e26743d31)](https://coveralls.io/github/andreypostal/php-pancake-object?branch=main)

Light and simple helper to work with value objects by providing a serializer and hydrator using PHP Attributes. It also provides a set of interfaces that allow you to customize the lib behavior to your needs.

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

[](#installation)

```
composer require andreypostal/php-pancake-object

```

Usage
-----

[](#usage)

### Attributes usage

[](#attributes-usage)

Currently, we have three main attributes available:

- ValueObject
- Item
- SkipItem

When creating your **Value Objects** you just need to add the attribute `Item`to each property that you want to hydrate/serialize.

```
use \Andrey\PancakeObject\Attributes\Item;

// { "id": 123, "name": "my name" }
class MyObject {
    #[Item]
    public int $id;
    #[Item(default: 'default name')]
    public string $name;
}
```

In the case where you want to serialize/hydrate every property from an object

```
use \Andrey\PancakeObject\Attributes\ValueObject;

// { "id": 123, "name": "my name" }
#[ValueObject]
class MyObject {
    public int $id;
    public string $name;
}
```

You can also combine both when need to add custom key, make an item required or even just skip some property.

```
use \Andrey\PancakeObject\Attributes\ValueObject;
use \Andrey\PancakeObject\Attributes\Item;
use \Andrey\PancakeObject\Attributes\SkipItem;

// { "id": 123, "custom_name": "my name" }
#[ValueObject]
class MyObject {
    public int $id;
    #[Item(key: 'custom_name')]
    public string $name;
    #[SkipItem]
    public string $ignoredProperty;
}
```

In case the items are required to exist in the data array being used for hydration, you can add the required flag in the attribute to include some basic required validation.

```
use \Andrey\PancakeObject\Attributes\Item;

// { "id": 123 } or { "id": 123, "name": "my name" }
class MyObject {
    #[Item(required: true)]
    public int $id;
    #[Item]
    public string $name;
}
```

When some of the keys in your data are different from your object, you can include the custom key in the attribute.

```
use \Andrey\PancakeObject\Attributes\Item;

// { "customer_name": "the customer name" }
class MyObject {
    #[Item(key: 'customer_name')]
    public string $name;
}
```

Also, if you have a property that is an array of other object, you can inform the class in the attribute using the `type` option. This will work as a hint so the hydrator can instantiate the appropriate object. This works with enums as well.

```
use \Andrey\PancakeObject\Item;
use \MyNamespace\MyOtherObj;

// { "list": [ { "key": "value" } ] }
class MyObject {
    /** @var MyOtherObj[] */
    #[Item(type: MyOtherObj::class)]
    public array $list;
}
```

The type option can be used to validate that all the items in an array have some desired type as well, like "string", "integer"...

You can define a default value for an item using the "default" field when using the Item attribute:

```
use \Andrey\PancakeObject\Attributes\Item;

class MyObject {
    #[Item]
    public int $id;
    #[Item(default: 'default name')]
    public string $name;
}
```

### Hydrator and Serializer

[](#hydrator-and-serializer)

In order to hydrate some value object following the attribute rules, you just need to use the SimpleHydrator class. We also provide interfaces that allow you to customize the hydrator and key mapping strategy used (like snake case to pascal case).

The same applies to the SimpleSerializer class, used to serialize an object into an data array.

```
use \Andrey\PancakeObject\SimpleHydrator;
use \Andrey\PancakeObject\SimpleSerializer;
use \MyNamespace\MyObject;

// Hydration phase
$hydrator = new SimpleHydrator();

$dataArray = $request->body->toArray();
$myObject = $hydrator->hydrate($dataArray, MyObject::class);

// Serialization phase
$serializer = new SimpleSerializer();
$arr = $serializer->serialize($myObject);
```

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance52

Moderate activity, may be stable

Popularity26

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity33

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

Recently: every ~32 days

Total

7

Last Release

332d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15055086?v=4)[Andrey Postal](/maintainers/andreypostal)[@andreypostal](https://github.com/andreypostal)

---

Top Contributors

[![andreypostal](https://avatars.githubusercontent.com/u/15055086?v=4)](https://github.com/andreypostal "andreypostal (24 commits)")

---

Tags

deserializationdeserializerhydratehydratorparserphpserializationserializervalue-objectparserserializerhydratorvalue objects

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/andreypostal-php-pancake-object/health.svg)

```
[![Health](https://phpackages.com/badges/andreypostal-php-pancake-object/health.svg)](https://phpackages.com/packages/andreypostal-php-pancake-object)
```

###  Alternatives

[nikic/php-parser

A PHP parser written in PHP

17.4k954.1M2.5k](/packages/nikic-php-parser)[doctrine/lexer

PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.

11.2k959.9M160](/packages/doctrine-lexer)[masterminds/html5

An HTML5 parser and serializer.

1.8k269.7M322](/packages/masterminds-html5)[matomo/device-detector

The Universal Device Detection library, that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), clients (browsers, media players, mobile apps, feed readers, libraries, etc), operating systems, devices, brands and models.

3.5k26.4M183](/packages/matomo-device-detector)[laktak/hjson

JSON for Humans. A configuration file format with relaxed syntax, fewer mistakes and more comments.

86245.3k14](/packages/laktak-hjson)[metroplex-systems/edifact

Parser and Serializer for UN/EDIFACT messages

36410.4k](/packages/metroplex-systems-edifact)

PHPackages © 2026

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