Download the PHP package popcorn4dinner/presenters without Composer
On this page you can find all versions of the php package popcorn4dinner/presenters. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download popcorn4dinner/presenters
More information about popcorn4dinner/presenters
Files in popcorn4dinner/presenters
Package presenters
Short Description A non-opinionated implementation of the presenter pattern
License MIT
Informations about the package presenters
- Presenters
** Installation
+BEGIN_SRC sh
composer require popcorn4dinner/presenters
+END_SRC
** Usage The idea behind presenters is to separate the presentation logic from your domain models. As a side effect you also only expose only needed functions and therefore the smallest possible interface to the render process.
*** Example
**** Simple user and Presenter class
+BEGIN_SRC php
class SimpleUser { private $firstName = "Florian"; private $lastName = "Thylman"; private $age = 13;
public function getFirstName()
{
return $this->firstName;
}
public function getLastName()
{
return $this->lastName;
}
public function getAge()
{
return $this->age;
}
public function setAge($newAge)
{
$this->age = $newAge;
}
}
+END_SRC
+BEGIN_SRC php
class ExamplePresenter extends AbstractPresenter {
protected const DELEGATED_METHODS = ['getFirstName', 'getLastName'];
public function getFullName()
{
return $this->getFirstName() . ' ' . $this->getLastName();
}
public function getAge()
{
return $this->original->getAge() . ' years';
}
}
+END_SRC
**** Example usage Controller:
+BEGIN_SRC php
class UserController { public function view(Request $request, FindUserHandler $handler, \Twig_Environment $twig) { $command = $this->commandPopulator->populate(new FindUser(), $request); $user = $handler->execute($command, $user);
$response = new Response(
$twig->render(
'users/view.twig',
[
'user' => new UserPresenter($user)
]
)
);
return $response;
}
}
+END_SRC
View: