terranet/presentable

There is no license information available for the latest version (v1.0) of this package.

Simple Object Presenter

v1.0 2016-08-26 11:16 UTC

This package is not auto-updated.

Last update: 2024-11-07 04:05:30 UTC


README

Move presentation logic out from the Object class.

Installation

composer require terranet/presentable

Use Case

<?php

class Post implements PresentableInterfacee
{
    use PresentableTrait;
    
    protected $presenter = PostPresenter::class;
}
<?php

class PostPresenter extends Presenter
{
    public function title()
    {
        return '<a href="/posts/read/' . $this->presentable->url . '">' . $this->presentable->title . '</a>';
    }
}

In view, instead of calling $post->title, call Presenter's method $post->present()->title;

Enjoy!