Presentable is a package for making your objects presentable. It uses the presenter pattern to allow moving presentation logic out of other objects.
<?php
namespace Acme;
use Rowofpixels\Presentable\Presenter;
class PersonPresenter extends Presenter
{
public function fullName()
{
return $this->entity->firstName . ' ' . $this->entity->lastName;
}
}
...
use Rowofpixels\Presentable\PresentableTrait;
class Person
{
use PresentableTrait;
protected $presenter = 'Acme\PersonPresenter';
}
...
$person = new \Acme\Person();
$person->firstName = 'Michael';
$person->lastName = 'Bluth';
$person->present()->fullName();
$person->present()->fullName; // Attribute syntax also works