PHPackages                             gobline/presenter - 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. gobline/presenter

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

gobline/presenter
=================

Presenter component

v2.0.0(10y ago)226BSD-3-ClausePHPPHP &gt;=5.6.0

Since Oct 22Pushed 9y ago1 watchersCompare

[ Source](https://github.com/gobline/presenter)[ Packagist](https://packagist.org/packages/gobline/presenter)[ Docs](https://github.com/gobline)[ RSS](/packages/gobline-presenter/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (4)Used By (0)

Presenter component
===================

[](#presenter-component)

The Presenter component allows you to decorate your model objects with methods used by your views. A typical example used to demonstrate the use for presenters, is a presenter method formatting a date from the model in a more readable format for the user.

Gobline\\Presenter\\Presenter
-----------------------------

[](#goblinepresenterpresenter)

By decorating your model objects with a `Gobline\Presenter\Presenter` instance, you will be able to access private/protected fields as you would access a public field, as long as there is a getter defined.

```
class Property
{
    protected $price;
    protected $nbRooms;
    protected $livingArea;
    protected $publicationDate;

    public function __construct($price, $nbRooms, $livingArea)
    {
        $this->price = $price;
        $this->nbRooms = $nbRooms;
        $this->livingArea = $livingArea;
        $this->publicationDate = new \DateTime();
    }
    public function getPrice() { return $this->price; }
    public function getNbRooms() { return $this->nbRooms; }
    public function getLivingArea() { return $this->livingArea; }
    public function getPublicationDate() { return $this->publicationDate; }
}

$property = new Property(650, 1, 120);
$property = new Gobline\Presenter\Presenter($property);
```

```
Living area:livingArea ?>
```

This is simply done by PHP's magic methods `__get` and `__call`.

In order to add behavior to your model objects for view formatting, you will have to create your own presenter:

```
class PropertyPresenter extends Gobline\Presenter\Presenter
{
    public function __construct(Property $subject)
    {
        parent::__construct($subject);
    }

    public function getPublicationDate()
    {
        return $this->subject->getPublicationDate()->format('d/m/Y');
    }

    public function getNbRooms()
    {
        $nbRooms = $this->subject->getNbRooms();

        if ($nbRooms === 0) {
            return 'Studio';
        }

        if ($nbRooms === 1) {
            return $nbRooms.' room';
        }

        return $nbRooms.' rooms';
    }
}

$property = new Property(650, 1, 120);
$property = new PropertyPresenter($property);
```

```
Living area:livingArea ?>
Number of rooms:nbRooms ?>
Publication date:publicationDate ?>
```

Gobline\\Presenter\\PresenterFactoryInterface
---------------------------------------------

[](#goblinepresenterpresenterfactoryinterface)

A presenter factory is useful when your presenter requires dependencies. You inject the dependencies once in the factory, and the factory will create the presenter on demand with all its required dependencies.

```
use Gobline\Translator\Translator;

class PropertyPresenterFactory implements Gobline\Presenter\PresenterFactoryInterface
{
    protected $translator;

    public function __construct(Translator $translator)
    {
        $this->translator = $translator;
    }

    public function createPresenter($property)
    {
        return new PropertyPresenter($property, $this->translator);
    }
}
```

You would then typically inject this factory into the object that will return the decorated model instances to the view. That object can now return decorated model instances like the following:

```
$property = $this->propertyPresenterFactory->createPresenter($property);
```

Gobline\\Presenter\\CollectionPresenter
---------------------------------------

[](#goblinepresentercollectionpresenter)

When the view needs to display data from an array of model instances, we then need to wrap this array in order to return our presenters (decorated model instances) for each array access. The collection wrapper requires a presenter factory in order to return the right presenters.

```
$results = $this->orm->findAll();
$results = new Gobline\Presenter\CollectionPresenter($results, $this->propertyPresenterFactory);
```

Gobline\\Presenter\\PresenterTrait
----------------------------------

[](#goblinepresenterpresentertrait)

The presenter trait allows your private/protected properties to be accessed as public properties.

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

[](#installation)

You can install the Presenter component using the dependency management tool [Composer](https://getcomposer.org/). Run the *require* command to resolve and download the dependencies:

```
composer require gobline/presenter

```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

3

Last Release

3862d ago

Major Versions

v1.1.0 → v2.0.02015-12-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/1564a230fe2f5125b0504cf6b6fe1e829face1a5d20ec663b3b8d22843312c7d?d=identicon)[mdecaffmeyer](/maintainers/mdecaffmeyer)

---

Tags

presentergobline

### Embed Badge

![Health badge](/badges/gobline-presenter/health.svg)

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

###  Alternatives

[oat-sa/tao-core

TAO core extension

66140.1k108](/packages/oat-sa-tao-core)[sylius/promotion

Flexible promotion management for PHP applications.

28495.4k13](/packages/sylius-promotion)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3691.3k16](/packages/netgen-layouts-core)[culturegr/presenter

Eloquent Model Presenter for Laravel applications

141.4k](/packages/culturegr-presenter)

PHPackages © 2026

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