gavande/eventy
Composer 安装命令:
composer require gavande/eventy
包简介
The WordPress filter/action system in Laravel
README 文档
README
Actions and filters in Laravel. WordPress-style.
Bring the event system you've learned to love to your Laravel project. Eventy (for lack of a better name) is a simple action and filter system.
About
Actions are pieces of code you want to execute at certain points in your code. Actions never return anything, but merely serves as the option to hook in to your existing code without having to mess things up.
Filters are made to modify entities. They always return some kind of value. By default they return their first parameters, and you should too.
Installation
- Install using Composer
composer require gavande/eventy
If you're using Laravel 5.5 you can start using the package at this point. Eventy is auto-discovered by the Laravel framework.
- Add the service provider to the providers array in your
config/app.php.
'TorMorten\Eventy\EventServiceProvider',
- Add the facade in
config/app.php
'Eventy' => TorMorten\Eventy\Facades\Events::class,
Usage
Actions
Anywhere in your code you can create a new action by so:
Eventy::action('my.hook', 'awesome');
The first parameter is the name of the hook, you will use this at a later point when you'll be listening to your hook. All subsequent parameters are sent to the action as parameters. These can be anything you'd like. For example you might want to tell the listeners that this is attached to a certain model. Then you would pass this as one of the arguments.
To listen to your hooks, you attach listeners. These are best added to your AppServiceProvider boot() method.
For example if you wanted to hook in to the above hook, you could do:
Eventy::addAction('my.hook', function($what) {
echo 'You are '. $what;
}, 20, 1);
Again the first argument must be the name of the hook. The second would be a callback. This could be either a Closure, a string referring to a class in the application container (MyNamespace\Http\Listener@myHookListener), an array callback ([$object, 'method']) or a globally registered function function_name. The third argument is the priority of the hook. The lower the number, the earlier the execution. The fourth parameter specifies the number of arguments your listener accepts.
Filters
Filters work in much of the same way as actions, and have the exact same build-up as actions. The most significat difference is that filters always return their value.
To add a filter:
$value = Eventy::filter('my.hook', 'awesome');
If no listeners are attached to this hook, the filter would simply return 'awesome'.
This is how you add a listener to this filter (still in the AppServiceProvider):
Eventy::addFilter('my.hook', function($what) { $what = 'not '. $what; return $what; }, 20, 1);
The filter would now return 'not awesome'. Neat!
You could use this in conjunction with the previous hook.
Eventy::addAction('my.hook', function($what) { $what = Eventy::filter('my.hook', 'awesome'); echo 'You are '. $what; });
Using in Blade
There are two directives availiable so you can use this in your Blade templates.
Adding the same action as the one in the action example above:
@action('my.hook', 'awesome')
Adding the same filter as the one in the filter example above:
You are @filter('my.hook', 'awesome')
gavande/eventy 适用场景与选型建议
gavande/eventy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 01 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「event」 「wordpress」 「events」 「filter」 「HOOK」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gavande/eventy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gavande/eventy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gavande/eventy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Библиотека для реализаций паттерна Pub/Sub
Wireless Cross-Component Communication
A powerful event calendar Tool for Laravel's Nova 5.
Symfony bundle for broadway/broadway.
Command bus implementation: Commands and domain events
This is an Event Emitter equivalent to Node.js' Event Emitter.
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-01-17