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

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

joebengalen/payload
===================

Domain payload library

110PHP

Since Sep 8Pushed 10y ago1 watchersCompare

[ Source](https://github.com/JoeBengalen/Payload)[ Packagist](https://packagist.org/packages/joebengalen/payload)[ RSS](/packages/joebengalen-payload/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Payload
=======

[](#payload)

[![Build Status](https://camo.githubusercontent.com/9f4a30ab13465bce4c50e88f1b55fd80b4b9a05fc1dac3b7e4d3ffdf90de6d4c/68747470733a2f2f7472617669732d63692e6f72672f4a6f6542656e67616c656e2f5061796c6f61642e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/JoeBengalen/Payload)[![Coverage Status](https://camo.githubusercontent.com/c5c5608f71c857ae40fa2d5fb2f540f8b47ad3aa032b0af9cf55cd0ca4fd3018/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f4a6f6542656e67616c656e2f5061796c6f61642f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/JoeBengalen/Payload?branch=master)[![SensioLabsInsight](https://camo.githubusercontent.com/98f2fe8538b72d0781c26218bc6e61f08a1b74106b8d33b0579e7370c712e056/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f66316431623561652d336433382d343533362d396562372d6337383931643430666466642f6d696e692e706e67)](https://insight.sensiolabs.com/projects/f1d1b5ae-3d38-4536-9eb7-c7891d40fdfd)[![Total Downloads](https://camo.githubusercontent.com/4c8aafd7cf446437f0f3393b3f696ede4f419107f5e9d22b6587ffa89a22102e/68747470733a2f2f706f7365722e707567782e6f72672f6a6f6562656e67616c656e2f7061796c6f61642f646f776e6c6f616473)](https://packagist.org/packages/joebengalen/payload)[![License](https://camo.githubusercontent.com/2ede6ac41be5e9a010f77c159a25c743a5caa00eeb93b7d61dfd2358899d8143/68747470733a2f2f706f7365722e707567782e6f72672f6a6f6562656e67616c656e2f7061796c6f61642f6c6963656e7365)](LICENSE.md)

Payload is a data transfer object between the domain layer and the application layer. The idea is that for every method you call on the domain service/access layer (domain API), you will receive a Payload instance as answer.

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

[](#installation)

Via [Composer](https://getcomposer.org)

```
$ composer require joebengalen/payload
```

Usage
-----

[](#usage)

### Fetch vs Command methods

[](#fetch-vs-command-methods)

There are two types of methods in a domain access layer: First you have **fetch** methods, which **asks** for data. Second you have **command** methods, which tell the domain to **perform** a certain action. The Payload status will tell you if the method was successful or not. Apart from the status the Payload may contain additional information, such as the requested data or an exception if something went wrong.

### Payload status

[](#payload-status)

The Payload status can be set and read with the following methods:

- `setStatus($status)`
- `getStatus()`

The following Payload statuses are available.

- `PayloadStatus::FOUND` Requested data found
- `PayloadStatus::NOT_FOUND` Requested data not found
- `PayloadStatus::SUCCESS` Action succeeded
- `PayloadStatus::INVALID` Invalid input
- `PayloadStatus::ERROR` Error during execution

*WARNING: Do not rely on the constant values as they may change over time! Always use the constants by their name.*

### PayloadFactory

[](#payloadfactory)

To make the creation of the Payload objects easier there is a `PayloadFactory`available. This factory contains methods to create payload objects with every available status or one without a status.

- `createPayload()` Create a new Payload object
- `createSuccessPayload()` Create a new Payload object with status success
- `createFoundPayload()` Create a new Payload object with status found
- `createNotFoundPayload()` Create a new Payload object with status not found
- `createInvalidPayload()` Create a new Payload object with status invalid
- `createErrorPayload()` Create a new Payload object with status error

### Payload data

[](#payload-data)

Apart from the status the Payload can contain a message, the input and the output of the domain method. To manage that data the following methods are available in the Payload class.

- `setMessage(string $message)`
- `getMessage()`
- `setInput(mixed $input)`
- `getInput()`
- `setOutput(mixed $input)`
- `getOutput()`

### PayloadInterface

[](#payloadinterface)

Payload objects should only be created and modified within the domain. If the domain method has `PayloadInterface` as return type, only the getter methods will be visible/available to the application.

Of course you could still modify the payload by methods outside of the interface, but it will at least show you should not use the setter methods.

Best practice
-------------

[](#best-practice)

Explanation of how I intended the Payload objects to be used. You can make up your own set of rules, but it is recommended to use the same rules throughout the whole domain.

### Payload status

[](#payload-status-1)

Fetch methods can return the following payload statuses

- `PayloadStatus::FOUND`
- `PayloadStatus::NOT_FOUND`
- `PayloadStatus::INVALID`
- `PayloadStatus::ERROR`

Command methods can return the following payload statuses

- `PayloadStatus::SUCCESS`
- `PayloadStatus::INVALID`
- `PayloadStatus::ERROR`

### Payload input/output

[](#payload-inputoutput)

For each payload status the following input/output data should be provided

- `PayloadStatus::FOUND`

    - input: `null` or named array of fetch parameters (if any)
    - output: found entity or collection
- `PayloadStatus::NOT_FOUND`

    - input: named array of fetch parameters (if any)
    - output: `null`
- `PayloadStatus::SUCCESS`

    - input: `null`
    - output: created/updated/deleted entity or other relevant data if available
- `PayloadStatus::INVALID`

    - input: named array of the parameters
    - output: list of error messages
- `PayloadStatus::ERROR`

    - input: named array of the parameters
    - output: thrown exception

This way you will always have the information you may need. If anything goes wrong (not found, invalid or error status) you will have the input parameter to see why. Optionally you may choose to always include the input argument in the payload.

### Payload message

[](#payload-message)

Payload messages are optional. They may contain a general message about the status. Such a message could be handy to provide the user with a friendly message in the application. I would recommend to at least be consistent throughout the whole domain whether you return a message or not.

Examples:

- Could not find user
- User was successfully updated
- Message successfully marked as read
- Invalid comment data provided
- Could not add project

Change log
----------

[](#change-log)

Please see the [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

This project uses [PHPSpec](http://phpspec.net) for testing.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/47732f0e5bc5d319cc52db1313312daa37279fe5fa16abf5bdd5a77e65347b1d?d=identicon)[JoeBengalen](/maintainers/JoeBengalen)

---

Top Contributors

[![JoeBengalen](https://avatars.githubusercontent.com/u/11173689?v=4)](https://github.com/JoeBengalen "JoeBengalen (9 commits)")

### Embed Badge

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

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

###  Alternatives

[n98/junit-xml

JUnit XML Document generation library

168.7M8](/packages/n98-junit-xml)[shtumi/useful-bundle

Symfony ShtumiUsefulBundle

11099.5k](/packages/shtumi-useful-bundle)

PHPackages © 2026

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