定制 popcorn4dinner/presenters 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

popcorn4dinner/presenters

Composer 安装命令:

composer require popcorn4dinner/presenters

包简介

A non-opinionated implementation of the presenter pattern

README 文档

README

Installation

composer require popcorn4dinner/presenters

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

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;
    }
}
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';
    }
}

Example usage

Controller:

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;
    }
}

View:

<div>
 Name: {% $user->getFullName() %} // Florian Tylman
 Age: {% $user->getAge() %} // 13
</div>

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-04-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固