2017 © Pedro Peláez
 

library looker

A really simple PHP view presenter based on Jeffery Ways laracasts\Presenter class

image

warrickbayman/looker

A really simple PHP view presenter based on Jeffery Ways laracasts\Presenter class

  • Saturday, April 15, 2017
  • by warrickbayman
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2,086 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 5 % Grown

The README.md

Looker

Build Status Stable Latest Unstable Version License, (*1)

A simple PHP presenter library., (*2)

Why

Well, it's quite common to separate your presentation code from your models. When I started with PHP I found myself doing things like:, (*3)

//User.php

class User extends Model
{
    public function fullName()
    {
        return $this->first_name . ' ' . $this->last_name;
    }
}

// view.php
fullName(); ?>

This is bad. So Looker separates your presentation stuff out of your models. It's based on the simple presentation library that Jeffery Way wrote for Laracasts., (*4)

Installation

Use composer:, (*5)

composer require warrickbayman/looker

Usage

In your model add the Looker\Presentable trait:, (*6)


use Looker\Traits\Presentable; class User { use Presentable; }

Create a new view presenter that extends the Looker\Presenter class, (*7)

use Looker\Presenter;

class User extends Presenter
{
    public function fullName()
    {
        return $this->entity->first_name . ' ' . $this->entity->last_name;
    }
}

Now, in your view:, (*8)

echo $this->present()->fullName;

From within the presenter, $this->entity is the associated model., (*9)

By default, Looker will look in the Http\Presenters namespace for presenter classes, but you can change that. Somewhere in your intialization, call the Looker::init method and pass in the class path for your presenters:, (*10)

Looker\Looker::init('Presenters');

You can also pass in a "suffix" if you like to do things like add the word "Presenter" to the end of your presenter classes:, (*11)

Looker\Looker::init('Presenters', 'Presenter');

Now Looker will look for UserPresenter instead of just User., (*12)

Overriding Model Members

Looker will automatically override model members. So you can do:, (*13)

echo $user->present()->dateOfBirth;

even if the dateOfBirth method or property doesn't exist on your presenter. Looker will first look for a method by the same name on the model. If a method doesn't exist, it will then look for a property by the same name. Looker will throw a OverrideFailed exception if there is no method or property to call., (*14)

The Versions

15/04 2017

dev-master

9999999-dev

A really simple PHP view presenter based on Jeffery Ways laracasts\Presenter class

  Sources   Download

MIT

The Development Requires

15/04 2017

1.0.1

1.0.1.0

A really simple PHP view presenter based on Jeffery Ways laracasts\Presenter class

  Sources   Download

MIT

The Development Requires

26/11 2015

1.0.0

1.0.0.0

A really simple PHP view presenter based on Jeffery Ways laracasts\Presenter class

  Sources   Download

MIT

The Development Requires

15/11 2015

0.2.0

0.2.0.0

A really simple PHP view presenter based on Jeffery Ways laracasts\Presenter class

  Sources   Download

MIT

The Development Requires

15/06 2015

0.1.1

0.1.1.0

A really simple PHP view presenter based on Jeffery Ways laracasts\Presenter class

  Sources   Download

MIT

The Development Requires