PHPackages                             dan-har/presentit - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. dan-har/presentit

ActiveLibrary[HTTP &amp; Networking](/categories/http)

dan-har/presentit
=================

Presentation and transformation of complex nested data structures for API

1.0.1(9y ago)1481MITPHP

Since Jan 28Pushed 7y ago1 watchersCompare

[ Source](https://github.com/dan-har/presentit)[ Packagist](https://packagist.org/packages/dan-har/presentit)[ RSS](/packages/dan-har-presentit/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (3)Used By (1)

presentit
=========

[](#presentit)

Presentit is an easy to use tool for custom presentations of nested data structures that are used in API responses.

```
Present::item($user)->with(function (User $user) {
    return [
        'id' => $user->id,
        'name' => $user->first_name . " " . $user->last_name,
        'image' => $user->image ?: Present::hidden(),
        'friends' => Present::each($user->friends)->with(function (User $friend) {
            return [
                //...
            ]
        })
    ];
})->show();
```

Features
--------

[](#features)

- Fluent interface to transform nested data structures
- Transformer classes for presentation logic code reuse.
- Callback transformers for inline data transformations.
- Control data properties visibility using the Hidden object instead of using if statements.

Adapters
--------

[](#adapters)

- [Laravel framework adapter](https://github.com/dan-har/presentit-laravel)

Docs
====

[](#docs)

- [Installation](#installation)
- [Basic usage](#basic-usage)

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

[](#installation)

Install using composer

```
composer require dan-har/presentit

```

Basic usage
-----------

[](#basic-usage)

The `Present` class is used for transforming single resource or a collection of resources.

Present a single resource by using the `item()` method.

```
$presentation = Present::item($user)->with(function (User $user) {
    return [
        'id' => $user->id,
        'first_name' => ucfirst($user->first_name),
        // ...
    ];
});
```

Present a list of resources using the `collection` or `each` methods. Each of the items in the list will be transformed using the transformer that is passed to the `each` method.

```
$presentation = Present::collection($usersList)->with(function (User $user) {
    return [
        'id' => $user->id,
        'first_name' => ucfirst($user->first_name),
        // ...
    ];
});
```

The `with` function excepts a `Transformer` and returns a `Presentation` object. To get the presentation data as array use the `show` method.

```
$array = $presentation->show();
```

Commonly usage of the `Presentation` is with an http response object. Usage example with Symphony `JsonResponse`

```
$response = new JsonResponse($presentation->show());

$response->send();
```

Hide keys using the `Hidden` object.

```
$presentation = Present::item($user)->with(function (User $user) {
    return [
        'id' => $user->id,
        'first_name' => ucfirst($user->first_name),
        'birthday' => $user->isBirthDayPublic() ? $user->birthday : Present::hidden() // or use Hidden::key()
        // ...
    ];
});
```

When a value in an array data structure is a `Hidden` type the key will not be presented. The above example presentation will be

```
$array = $presentation->show();

// if birthday is not public ->
// $array = [
//     'id' => $user->id,
//     'first_name' => ucfirst($user->first_name),
// ]
// birthday key is not visible.
```

The `with` method accepts a transformer. A transformer can be a `callable`, `Transformer` instance or a transformer class `string` name.

Using a `Transformer` class name `string`

```
class UserTransformer
{
    public function transform(User $user)
    {
        return [
            'id' => $user->id,
            'first_name' => ucfirst($user->first_name),
            // ...
        ];
    }
}

$presentation = Present::each($usersList)->with(UserTransformer::class);
```

Or with `Transformer` instance

```
$tranformer = new UserTransformer();

$presentation = Present::item($user)->with($transformer);
$presentation = Present::each($usersList)->with($transformer);
```

Nested presentation using a `Transformer` class

```
use Presentit\Present;

class UserTransformer
{
    public function transform(User $user)
    {
        return [
            'id' => $user->id,
            'first_name' => ucfirst($user->first_name),
            'friends' => $user->friends ? Present::each($user->friends)->with(UserTransformer::class) : [],
            // ...
        ];
    }
}

$presentation = Present::each($usersList)->with(UserTransformer::class);
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

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

Total

2

Last Release

3418d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3855298?v=4)[Daniel Harenberg](/maintainers/danhar)[@danhar](https://github.com/danhar)

---

Top Contributors

[![dan-har](https://avatars.githubusercontent.com/u/8581476?v=4)](https://github.com/dan-har "dan-har (12 commits)")

---

Tags

jsonapirestnestedtransformerpresentit

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dan-har-presentit/health.svg)

```
[![Health](https://phpackages.com/badges/dan-har-presentit/health.svg)](https://phpackages.com/packages/dan-har-presentit)
```

###  Alternatives

[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69122.6k](/packages/serpapi-google-search-results-php)[ismaeltoe/osms

PHP library wrapper of the Orange SMS API.

4540.5k](/packages/ismaeltoe-osms)[jsor/hal-client

A lightweight client for consuming and manipulating Hypertext Application Language (HAL) resources.

2226.0k1](/packages/jsor-hal-client)[elao/json-http-form-bundle

Adds support of JSON requests for Forms

356.1k](/packages/elao-json-http-form-bundle)

PHPackages © 2026

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