plank/laravel-hush
Composer 安装命令:
composer require plank/laravel-hush
包简介
A targeted version of the Laravel Frameworks withoutEvents method.
关键字:
README 文档
README
Laravel Hush
laravel-hush is a Laravel package that allows you to disable the observers and handlers for model events during the execution of a passed in closure. It functions as a more targetted version of the withoutEvents() method that ships with Laravel.
Table of Contents
Installation
You can install the package via composer:
composer require plank/laravel-hush
Usage
The package ships with one trait: HushesHandlers
To enable the functionality on a model, simply include the trait on it.
It implements four methods:
withoutObserver(string $observer, Closure $callback)
This method will disable any handlers in the provided class for all of the models observable events during the exection of the callback.
Example assuming User uses HushesHandlers. In this example no handlers from the entire UserObserver class will be called during the execution of the callback, for any observable event.
User::withoutObserver(UserObserver::class, function () { User::create(['name' => 'John Doe']); });
withoutObservers(array $observers, Closure $callback)
This method is the same as withoutObserver() but allows you to pass in an array of observer classes to disable.
For example:
User::withoutObservers([UserObserver::class, ExpirableObserver::class], function () { User::create(['name' => 'John Doe']); });
withoutHandler(string $event, Closure $callback, array $classes = [])
This method will disable handlers for the provided event during the execution of the callback.
When no classes are provided, it will disable all handlers for the event.
When classes are provided (including classes where handlers have been added statically) it will only disable the registered handlers which are from the provided classes.
In the following example all created event handlers would be disabled, however if there were creating handlers registered for example, those event handlers would still run.
User::withoutHandler('created', function () { User::create(['name' => 'John Doe']); });
In the following example all created event handlers defined in the User model would be disabled, however if there was a created handler in a UserObserver class (or anywhere else), it would still handle the event.
User::withoutHandler('created', function () { User::create(['name' => 'John Doe']); }, [User::class]);
withoutHandlers(array $events, Closure $callback, array $classes = [])
This method is the same as withoutHandler() but allows you to pass in an array of events to disable handlers for.
Credits
License
The MIT License (MIT). Please see License File for more information.
Security Vulnerabilities
If you discover a security vulnerability within siren, please send an e-mail to security@plankdesign.com. All security vulnerabilities will be promptly addressed.
Check Us Out!
Plank focuses on impactful solutions that deliver engaging experiences to our clients and their users. We're committed to innovation, inclusivity, and sustainability in the digital space. Learn more about our mission to improve the web.
plank/laravel-hush 适用场景与选型建议
plank/laravel-hush 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.51k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 10 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「plank」 「laravel-hush」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 plank/laravel-hush 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 plank/laravel-hush 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 plank/laravel-hush 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A package for keeping a history of your models' revisions and accessing your data as it was at an older date.
Retrieve all defined Models available in the Application or Vendor namespaces
A Laravel package to emit events based on the schema changes taking place during migration.
Snapshot Laravel Models
Create dynamic pages using polymorphic relationships and special Module classes
统计信息
- 总下载量: 13.51k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 18
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-25
