定制 lexisother/composer-patches-regex 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

lexisother/composer-patches-regex

Composer 安装命令:

composer require lexisother/composer-patches-regex

包简介

README 文档

README

A Composer plugin that allows for regex replacements patches using composer-patches.

Requirements

  • PHP 8.0.0 or higher
  • cweagans/composer-patches, preferably on commit 5269693119b245e273db052f12ab23d74aca26fc or later.
    • (note: this has to be installed through either dev-main or a custom repositories entry, as this package version isn't tagged on Packagist)

First of all, install the package using composer require lexisother/composer-patches-regex.

You should be prompted to allow the plugin to run code, if not, add the following to your composer.json:

{
  // ...
  "config": {
    "allow-plugins": {
      // ...
      "lexisother/composer-patches-regex": true
    }
  }
}

Defining patches

A patch looks simple. For the most part they are like regular composer-patches entries. You can read more about the general definition of patches here.

It is important to note that this plugin only supports patches defined with the expanded format.

Let's define a simple patch for a package with the following file in its root directory (vendor/scope/packagename):

I am some original text. I love being original.

We want to change the word "some" to "a bit of" and all instances of "original" to "copied". Our patch for this would look as follows:

{
  // ...
  "extra": {
    "patches": {
      "scope/packagename": [
        {
          "description": "A simple description of your patch here",
          "url": "./.gitignore",
          "extra": {
            "regex": {
              "files": {
                "someFile": [
                  {
                    "find": "/some/",
                    "replace": "a bit of"
                  },
                  {
                    "find": "/original/g",
                    "replace": "copied"
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

Note

When using the extra.regex.files key, please set the patch url to some arbitrary local file. composer-patches requires there to be a url, but we don't use it.

After running composer patches-relock and composer patches-repatch, vendor/scope/packagename/someFile would now look like this:

I am a bit of copied text. I love being copied.

Options

The plugin exposes some options to change the behaviour of the patcher. All of these options should be set directly inside extra.regex.

fromUrl

Setting this option to true makes the plugin ignore the files key and instead download the JSON from the specified URL. So if you are migrating your local patches to a file that is hosted remotely, please set your patch's url field to a valid URL pointing to your file.

ignoreErrors

Setting this option to true prevents composer-patches from failing with "No available patcher was able to apply patch" if any of your patches contain errors.

License

This project is dual-licensed under the Commons Clause and the GNU AGPL.

lexisother/composer-patches-regex 适用场景与选型建议

lexisother/composer-patches-regex 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.22k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 lexisother/composer-patches-regex 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 lexisother/composer-patches-regex 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: AGPL-3.0-or-later
  • 更新时间: 2024-11-21