dentro/laravel-patcher 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dentro/laravel-patcher

Composer 安装命令:

composer require dentro/laravel-patcher

包简介

Laravel patch scripts.

README 文档

README

A (migration like) patcher for a smoldering production update.

Total Downloads GitHub Workflow Status

Requirements:

  • PHP : 8.3+
  • Laravel: 9._ / 10._ / 11._ / 12._ / 13.*

Compatibility note: starting from v1.5.0, this package only supports PHP 8.3 and newer.

Installation

Do either of these methods below.

  • via shell
composer require dentro/laravel-patcher
  • adding "dentro/laravel-patcher": "^1.5" to composer.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:

  1. $container: \Illuminate\Container\Container

  2. $command: \Illuminate\Console\Command

    we frequently used $command property 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\Command here.

  3. $logger: \Illuminate\Log\Logger

    $logger will store log in storage/logs/patches.log. if you want to change it, add this line below in your config/logging.php in 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\Logger here

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 dentro/laravel-patcher 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 14.78k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 0
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-18