blessing/filter
Composer 安装命令:
composer require blessing/filter
包简介
Filters API for designing plugin system.
关键字:
README 文档
README
Filters API for designing and creating plugin system, within Laravel.
We used this in Blessing Skin Server.
The "Filters API" is similar with Filters API of WordPress, but comes with different API. And this package is designed for Laravel, so it may not work if you use it without Laravel.
💿 Install
Run Composer:
composer require blessing/filter
🔨 Usage
With Laravel's Auto-Discovery, you don't need to configure your Laravel application manually.
Currently this package doesn't provide Facade.
You must get instance by using type-hint in your controllers or using global resolve() helper function.
For example:
use Blessing\Filter; class MyController extends Controller { public function home(Filter $filter) { // } }
Add a filter
To add a filter for a specified hook, just call the add method:
$filter->add('hook_name', function ($value) { return $value; });
Note that the filter handler must return a value; otherwise, the value after applied will be null.
You also can pass a class which has a public method called filter as handler.
class MyFilter { public function filter($value) { return $value; } } $filter->add('hook_name', MyFilter::class); // or $filter->add('hook_name', 'MyFilter');
The class will be resolved from Laravel's service container, so you can use type-hint at the constructor of your class to resolve dependencies.
Additionally, you can specify the priority for your filter handler. Higher integer value indicates that it should come with higher priority.
Default priority is 20.
$filter->add('hook_name', function ($value) { return $value; }, 30); // Higher than default priority.
Apply a hook
You can call apply method to apply a hook:
$value = $filter->apply('hook_name', 'hi');
Then, the second argument you passed will be manipulated by filters.
Also, you can pass additional arguments as an array:
$value = $filter->apply('hook_name', 'hi', [$arg1, $arg2]);
Those additional arguments won't be manipulated by filters.
Remove all filters
To remove all filters for a specified hook, just:
$filter->remove('hook_name');
Totally...
This is a full example:
$filter->add('hook_name', function ($value, $arg1, $arg2) { if ($arg1 === '...') { return $value; } return $value.'!'; }); $value = $filter->apply('hook_name', 'hi', ['abc', 'def']); // You should get the text "hi!" here.
📄 License
MIT License (c) The Blessing Skin Team
blessing/filter 适用场景与选型建议
blessing/filter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.81k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 12 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wordpress」 「laravel」 「filters」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 blessing/filter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 blessing/filter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 blessing/filter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple filters for laravel
Livewire Filters is a series of Livewire components that provide you with the tools to do live filtering of your data from your own Livewire components.
A lightweight WordPress hook helper library. Register hooks before WordPress loads, run callbacks only once, and more.
Filters extension for Nette Framework
Laravel Advanced Filter
Provides a Data Grid tables for your Symfony project.
统计信息
- 总下载量: 3.81k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-27