jundayw/laravel-interceptor
Composer 安装命令:
composer require jundayw/laravel-interceptor
包简介
Sensitive Word Filter.
关键字:
README 文档
README
安装
推荐使用 PHP 包管理工具 Composer 软件包管理器安装:
composer require jundayw/laravel-interceptor
接下来,你需要使用 vendor:publish Artisan 命令发布的配置和迁移文件。
配置文件将会保存在 config 文件夹中:
php artisan vendor:publish --provider="Jundayw\LaravelInterceptor\InterceptorServiceProvider"
或单独发布配置文件
php artisan vendor:publish --tag=interceptor-config
或单独发布迁移文件
php artisan vendor:publish --tag=interceptor-migrations
最后,您应该运行数据库迁移。
php artisan migrate --path=database/migrations/2022_08_31_182223_create_interceptor_table.php
数据填充:
php artisan db:seed --class=InterceptorSeeder
自定义迁移
如果你不想使用默认迁移,你应该在 interceptor.php 配置文件中将 migration 设置为 false。
您可以通过执行以下命令导出默认迁移:
php artisan vendor:publish --tag=interceptor-migrations
扩展云端过滤器
本扩展包默认支持 Eloquent 驱动的 \Jundayw\LaravelInterceptor\Support\LocalFilter::class 本地过滤器,
<?php namespace App\Filter\Cloud; use Illuminate\Support\Collection; use Illuminate\Support\Traits\Macroable; use Jundayw\LaravelInterceptor\Contracts\Filter; class CloudFilter implements Filter { use Macroable; public function __construct() { // } public function handle(string $content, string $type): Collection { // cloud filter // $matches // $keywords // $replacement return collect([ 'type' => (string)$type,// 验证类型 'matches' => (array)$matches,// 内容中匹配到的敏感词集 'keywords' => (string)$keywords,// 敏感词 'replacement' => (string)$replacement,// 替换词或替换规则 ]); } }
编码实现后需要变更配置文件 interceptor.php 中过滤驱动 driver 为 App\Filter\Cloud\CloudFilter::class。
最佳实践
use Jundayw\LaravelInterceptor\Contracts\Interceptor; public function test(Interceptor $interceptor) { $content = '本校小额贷款,安全、快捷、方便、无抵押,随机随贷,当天放款,上门服务。'; $content = $interceptor->filter(content: $content, type: 'message', pass: function ($matches, $content) { return $content; }, review: function ($matches, $content) { // event(new ReViewEvent(...)); return $content; }, replace: function ($matches, $content, $collect) { return str_replace(current($matches), $collect->get('replacement'), $content); }, block: function ($matches, $content) { throw new \Exception('含有违规词'); }); echo $content; }
或者使用门面模式:
use Jundayw\LaravelInterceptor\Support\Facades\Interceptor; public function test() { $content = '本校小额贷款,安全、快捷、方便、无抵押,随机随贷,当天放款,上门服务。'; $content = Interceptor::filter(content: $content, type: 'message'); echo $content; }
jundayw/laravel-interceptor 适用场景与选型建议
jundayw/laravel-interceptor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 08 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「filter」 「laravel」 「interceptor」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jundayw/laravel-interceptor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jundayw/laravel-interceptor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jundayw/laravel-interceptor 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Nova searchable filter for belongsTo relationships.
REST client for PHP 7.4+
Symfony DataGridBundle
Data provider for yii2
This Laravel Nova package allows you to detach filters from the filter dropdown
Laravel filter elequent
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-31