warrickbayman/looker
最新稳定版本:1.0.1
Composer 安装命令:
composer require warrickbayman/looker
包简介
A really simple PHP view presenter based on Jeffery Ways laracasts\Presenter class
README 文档
README
A simple PHP presenter library.
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:
//User.php class User extends Model { public function fullName() { return $this->first_name . ' ' . $this->last_name; } } // view.php <?php echo $user->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.
Installation
Use composer:
composer require warrickbayman/looker
Usage
In your model add the Looker\Presentable trait:
use Looker\Traits\Presentable; class User { use Presentable; }
Create a new view presenter that extends the Looker\Presenter class
use Looker\Presenter; class User extends Presenter { public function fullName() { return $this->entity->first_name . ' ' . $this->entity->last_name; } }
Now, in your view:
echo $this->present()->fullName;
From within the presenter, $this->entity is the associated model.
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:
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:
Looker\Looker::init('Presenters', 'Presenter');
Now Looker will look for UserPresenter instead of just User.
Overriding Model Members
Looker will automatically override model members. So you can do:
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.
warrickbayman/looker 适用场景与选型建议
warrickbayman/looker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.08k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 06 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 warrickbayman/looker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 warrickbayman/looker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.08k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-06-04