PHPackages                             gpslab/payload - 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. gpslab/payload

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

gpslab/payload
==============

The simple infrastructure component for create payload message

v1.1.0(8y ago)7392MITPHPPHP &gt;=5.5.0CI failing

Since Jun 23Pushed 6y ago1 watchersCompare

[ Source](https://github.com/gpslab/payload)[ Packagist](https://packagist.org/packages/gpslab/payload)[ Docs](https://github.com/gpslab/payload)[ RSS](/packages/gpslab-payload/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (6)Versions (3)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/edf7fe0b78de909329261486d81aab7a058329e2a277b9e584dc72d9134136cd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6770736c61622f7061796c6f61642e7376673f6d61784167653d33363030266c6162656c3d737461626c65)](https://packagist.org/packages/gpslab/payload)[![Total Downloads](https://camo.githubusercontent.com/16eb66ed4b5d18263bc2537dfb8d386cf354e5fea1f8e2277eeb3848ced5a9d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6770736c61622f7061796c6f61642e7376673f6d61784167653d33363030)](https://packagist.org/packages/gpslab/payload)[![Build Status](https://camo.githubusercontent.com/b46800290bfeba217d110fd050fdb7ac8684d45d1a5595bde5ecef5d591ef151/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6770736c61622f7061796c6f61642e7376673f6d61784167653d33363030)](https://travis-ci.org/gpslab/payload)[![Coverage Status](https://camo.githubusercontent.com/8641903ca16802a36fc334cf77435142ec18a7677583a2ea705d7a3147457d4d/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6770736c61622f7061796c6f61642e7376673f6d61784167653d33363030)](https://coveralls.io/github/gpslab/payload?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/00e4bf4b37140091c071183382f22dd56e18f03dcfee5d6031a046b73f9fb879/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6770736c61622f7061796c6f61642e7376673f6d61784167653d33363030)](https://scrutinizer-ci.com/g/gpslab/payload/?branch=master)[![SensioLabs Insight](https://camo.githubusercontent.com/786e5dcb3224727bc822f864b5249c14d284233f34be50423fbd4093cc23049b/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f35663061373964652d636336352d346539622d623961622d6263623136616564636465632e7376673f6d61784167653d33363030266c6162656c3d534c496e7369676874)](https://insight.sensiolabs.com/projects/5f0a79de-cc65-4e9b-b9ab-bcb16aedcdec)[![StyleCI](https://camo.githubusercontent.com/1cd9a1a0ab6485d039d4aa412cfdd2f2a4148e0508e117dc1c94a144218b8028/68747470733a2f2f7374796c6563692e696f2f7265706f732f39323338303836372f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/92380867)[![License](https://camo.githubusercontent.com/daf4fa46154e60f1992879add401f837e0251216a895ebb88a2b3f2526c31526/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6770736c61622f7061796c6f61642e7376673f6d61784167653d33363030)](https://github.com/gpslab/payload)

The simple infrastructure component for create payload message
==============================================================

[](#the-simple-infrastructure-component-for-create-payload-message)

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

[](#installation)

Pretty simple with [Composer](http://packagist.org), run:

```
composer require gpslab/payload
```

Usage
-----

[](#usage)

This library automatically fill the properties of the object with payload data.

For example, create a simple message

```
class SimpleMessage extends PayloadMessage
{
    public $id = 0;

    public $name = '';
}
```

Fill the message

```
$message = new SimpleMessage([
    'id' => 123,
    'name' => 'foo',
]);

$message->id; // 123
$message->name; // foo
$message->payload(); // ['id' => 123, 'name' => 'foo']
```

> **Note**
>
> All fields specified in the payload must exist.

### Protected properties

[](#protected-properties)

You can use protected properties for data. It's convenient to make the properties as read-only.

```
class SimpleMessage extends PayloadMessage
{
    protected $id = 0;

    protected $name = '';

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

    public function name()
    {
        return $this->name;
    }
}
```

Fill the message

```
$message = new SimpleMessage([
    'id' => 123,
    'name' => 'foo',
]);

$message->id(); // 123
$message->name(); // foo
$message->payload(); // ['id' => 123, 'name' => 'foo']
```

> **Note**
>
> For fill private properties you must use setters.

### Property setters

[](#property-setters)

You can mark properties as private and use setters for fill it. This will ensure the security of data and control their type. You can mark the setters as protected to close the class from changes from the outside.

```
class SimpleMessage extends PayloadMessage
{
    private $id = 0;

    private $name = '';

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

    protected function setId(integer $id)
    {
        $this->id = $id;
    }

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

    protected function setName(string $name)
    {
        $this->name = $name;
    }
}
```

Fill the message

```
$message = new SimpleMessage([
    'id' => 123,
    'name' => 'foo',
]);

$message->id(); // 123
$message->name(); // foo
$message->payload(); // ['id' => 123, 'name' => 'foo']
```

### CQRS

[](#cqrs)

You can use payload in [CQRS](https://github.com/gpslab/cqrs) infrastructure.

Command to rename contact:

```
class RenameContactCommand extends PayloadCommand
{
    public $contact_id = 0;

    public $new_name = '';
}
```

Query for get contact by identity:

```
class ContactByIdentityQuery extends PayloadQuery
{
    public $id = 0;
}
```

### Domain Events

[](#domain-events)

You can use payload in [Domain Events](https://github.com/gpslab/domain-event).

Event, contact was renamed:

```
class RenamedContactEvent extends PayloadDomainEvent
{
    public $contact_id = 0;

    public $old_name = '';

    public $new_name = '';
}
```

### Serialize

[](#serialize)

You can serialize messages with Symfony [serializer](https://symfony.com/doc/current/components/serializer.html)component. For do it you can use `PayloadNormalizer` or `TypedPayloadNormalizer` and [encode](https://symfony.com/doc/current/components/serializer.html#encoders) result to JSON, XML, YAML, CSV, etc.

- `PayloadNormalizer` - can be used only for one class because he does not distinguish messages;
- `TypedPayloadNormalizer` - adds to the normalized data the type of message received from `MessageTypeResolver` service.

You can use `ClassNameMessageTypeResolver` as a simplify resolver. It use the last part of class name as a messages type.

- `\Acme\Demo\SomeMessage` converted to `SomeMessage`
- `\Acme_Demo_SomeMessage` converted to `SomeMessage`

Be careful with the use of this resolver and do not named message classes equally in different namespace.

License
-------

[](#license)

This bundle is under the [MIT license](http://opensource.org/licenses/MIT). See the complete license in the file: LICENSE

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.5% 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

2

Last Release

3230d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9a6415c83577efe7b70d9ae4a3bb12958adc11c16e530ff844ff217b0fd0c54a?d=identicon)[Peter Gribanov](/maintainers/Peter%20Gribanov)

---

Top Contributors

[![peter-gribanov](https://avatars.githubusercontent.com/u/1954436?v=4)](https://github.com/peter-gribanov "peter-gribanov (55 commits)")[![mathroc](https://avatars.githubusercontent.com/u/291531?v=4)](https://github.com/mathroc "mathroc (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

cqrsdomain-eventinfrastructurepayloadpayload-messagephppayloadcqrsinfrastructuredomain-eventpayload-message

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gpslab-payload/health.svg)

```
[![Health](https://phpackages.com/badges/gpslab-payload/health.svg)](https://phpackages.com/packages/gpslab-payload)
```

###  Alternatives

[prooph/service-bus

PHP Enterprise Service Bus Implementation supporting CQRS and DDD

4421.4M32](/packages/prooph-service-bus)[ecotone/ecotone

Supporting you in building DDD, CQRS, Event Sourcing applications with ease.

558549.8k17](/packages/ecotone-ecotone)[aura/payload

A Domain Payload implementation.

56370.4k9](/packages/aura-payload)[prooph/event-store-bus-bridge

Marry CQRS with Event Sourcing

37518.3k11](/packages/prooph-event-store-bus-bridge)[aura/payload-interface

An interface package for Domain Payload implementations.

13392.7k4](/packages/aura-payload-interface)[headsnet/domain-events-bundle

Integrates domain events into your Symfony application

4216.5k](/packages/headsnet-domain-events-bundle)

PHPackages © 2026

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