PHPackages                             krak/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. [Templating &amp; Views](/categories/templating)
4. /
5. krak/presenter

ActiveLibrary[Templating &amp; Views](/categories/templating)

krak/presenter
==============

Small and simple implementation of the presenter design pattern

v2.0.0(11y ago)13.6kMITPHPPHP ~5.3

Since Sep 25Pushed 8y ago1 watchersCompare

[ Source](https://github.com/krakphp/presenter)[ Packagist](https://packagist.org/packages/krak/presenter)[ Docs](https://github.com/bighead-dev/krak-presenter)[ RSS](/packages/krak-presenter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (6)Used By (0)

Krak Presenter
==============

[](#krak-presenter)

Simple yet powerful implementation of the presenter pattern.

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

[](#installation)

install via composer.

```
{
    "repositories": [
        {
            "type": "vcs",
            "url": "http://gitlab.bighead.net/bighead/krak-presenter.git"
        }
    ],
    "require": {
        "krak/presenter": "~2.0",

        /* only if you use the CachePresenter */
        "doctrine/cache": "~1.0",

        /* include if you use the EventListener\ViewListener */
        "symfony/event-dispatcher": "~2.0",
        "symfony/http-kernel": "~2.0",
        "symfony/http-foundation": "~2.0",

        /* include if you use the Provider\ViewPresenterServiceProvider */
        "pimple/pimple": "~3.0"
    }
}
```

Design
------

[](#design)

The Krak Presenters are broken up into 3 main components: Presenters, Decorators, and View Models.

The Presenters and Decorators all implement the `Presenter` interface:

```
interface Presenter
{
    /**
     * Present the view and return the content associated with it
     * @param mixed $view
     * @return string
     */
    public function present($view);

    /**
     * Whether or not the presenter can actually present the data/view
     * @param mixed $data
     * @return bool
     */
    public function canPresent($view);
}
```

A presenter/decorator will accept a view model to present and then return it's contents.

So the call

```
$content = $presenter->present($view);
```

will always return the content associated with view.

Presenters
----------

[](#presenters)

The Presenters will take view models and "present" them i.e. render them into a string response. This library comes bundled with 2 different presenters: View and Mock.

The View presenter will take a View model and return the appropriate content from the view file associated with the View model.

The Mock presenter is primarily used for testing, but it's just a simple wrapper around the [SplObjectStorage](http://php.net/manual/en/class.splobjectstorage.php).

### ViewPresenter

[](#viewpresenter)

```
