dentro/laravel-patcher
Composer 安装命令:
composer require dentro/laravel-patcher
包简介
Laravel patch scripts.
README 文档
README
A (migration like) patcher for a smoldering production update.
Requirements:
- PHP : 8.3+
- Laravel: 9._ / 10._ / 11._ / 12._ / 13.*
Compatibility note: starting from
v1.5.0, this package only supports PHP8.3and newer.
Installation
Do either of these methods below.
- via shell
composer require dentro/laravel-patcher
- adding
"dentro/laravel-patcher": "^1.5"tocomposer.json
{
"require": {
"dentro/laravel-patcher": "^1.5"
}
}
Post Installation
this process is optional, you can skip it though.
patches table creation.
php artisan patcher:install
Usage
Create New Patch
for creating a new patch, you need to run these following command
php artisan make:patch what_do_you_want_to_patch
After run that command, you will see new file in patches folder.
That file will be like:
<?php use Dentro\Patcher\Patch; class WhatDoYouWantToPatch extends Patch { public function patch() { // } }
Method patch on this file will be filled with your logic.
in Dentro\Patcher\Patch there is some useful properties
that you can use for supporting your patch such as:
-
$container: \Illuminate\Container\Container -
$command: \Illuminate\Console\Commandwe frequently used
$commandproperty to print process that we're doing. example:$this->command->warn('i patch something danger!'); $this->command->confirm('do you wish to continue?');
you can learn more about
\Illuminate\Console\Commandhere. -
$logger: \Illuminate\Log\Logger$loggerwill store log instorage/logs/patches.log. if you want to change it, add this line below in yourconfig/logging.phpin channels section.[ 'channels' => [ 'patcher' => [ 'driver' => 'patcher', // you can change me if you want 'path' => storage_path('logs/patches.log'), // change me ], ], ];you can learn more about
\Illuminate\Log\Loggerhere
Show Patch Status
php artisan patcher:status
Example:
➜ php artisan patcher:status +------+---------------------------------------+-------+ | Ran? | Patch | Batch | +------+---------------------------------------+-------+ | Yes | 2020_09_29_190531_fix_double_sections | 1 | | Yes | 2020_10_09_124616_add_attachment_beep | 1 | +------+---------------------------------------+-------+
Run Pending Patch(es)
php artisan patcher:run
Example:
➜ php artisan patcher:run Patches table created successfully. Patching: 2020_09_29_190531_fix_double_sections Patched: 2020_09_29_190531_fix_double_sections (0.03 seconds) Patching: 2020_10_09_124616_add_attachment_beep Patched: 2020_10_09_124616_add_attachment_beep (0.06 seconds)
Conditional Patch
You might need to skip single patch when run php artisan patcher:run.
Due to patch is unnecessary or patch is not eligible to run in your environment.
Here you can add the eligible method to your patch class to evaluate the condition
before running the patch method.
<?php use Dentro\Patcher\Patch; use App\Models\User; class WhatDoYouWantToPatch extends Patch { public function eligible(): bool { return User::query()->where('id', 331)->exists(); } public function patch() { $user = User::query()->find(331); // do something with user. } }
then the output of php artisan patcher:run will be:
➜ php artisan patcher:run
Patching: 2020_09_29_190531_fix_double_sections
Skipped: 2020_09_29_190531_fix_double_sections is not eligible to run in current condition.
Patching: 2020_10_09_124616_add_attachment_beep
Patched: 2020_10_09_124616_add_attachment_beep (0.06 seconds)
Perpetual Patch
In some cases you might also want to run patches script indefinitely, you can change isPerpetual
property on your patch file to true
class WhatDoYouWantToPatch extends Patch { public bool $isPerpetual = true; }
dentro/laravel-patcher 适用场景与选型建议
dentro/laravel-patcher 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.78k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2022 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 dentro/laravel-patcher 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dentro/laravel-patcher 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 14.78k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-03-18