codewithkyrian/platform-package-installer 问题修复 & 功能扩展

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

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

codewithkyrian/platform-package-installer

Composer 安装命令:

composer require codewithkyrian/platform-package-installer

包简介

A Composer plugin for platform-aware distribution URL resolution

README 文档

README

The Composer Platform Package Installer is a powerful plugin for platform-aware distribution URL resolution.

The core behavior is simple:

  • Your package declares platform-specific artifact URLs or URL templates in composer.json
  • At install time, the plugin picks the best URL for the current OS/architecture
  • It resolves placeholders (built-in {version} plus optional custom variables)
  • It tells Composer to download and install the package from that resolved URL

Requirements

  • PHP 8.1+
  • Composer 2+

Installation

Install the plugin using Composer:

composer require codewithkyrian/platform-package-installer

Then change your package type to platform-package in composer.json:

{
  "name": "org/your-platform-package",
  "type": "platform-package",
  "require": {
    "codewithkyrian/platform-package-installer": "^2.0"
  }
}

Core Configuration

All core behavior is configured in composer.json under extra.artifacts.

Legacy extra.platform-urls is still supported for backward compatibility, but is deprecated.

Format A: Simple (no custom variables)

Use this when:

  • you are using direct artifact URLs with no placeholders, or
  • {version} is the only placeholder you need.
{
  "extra": {
    "artifacts": {
      "darwin-arm64": "https://cdn.example.com/pkg/{version}/darwin-arm64.zip",
      "linux-x86_64": "https://cdn.example.com/pkg/{version}/linux-x86_64.tar.gz",
      "all": "https://cdn.example.com/pkg/{version}/universal.zip"
    }
  }
}

Format B: Extended (custom variables + defaults)

Use this when templates include additional placeholders beyond {version}.

{
  "extra": {
    "artifacts": {
      "urls": {
        "darwin-arm64": "https://cdn.example.com/pkg/{version}/variant-{runtime}/darwin-arm64.zip",
        "linux-x86_64": "https://cdn.example.com/pkg/{version}/variant-{runtime}/linux-x86_64.tar.gz"
      },
      "vars": {
        "runtime": "gpu"
      }
    }
  }
}

Application-Level Variable Overrides

Consumers of your platform package can override variables from their root project:

{
  "extra": {
    "platform-packages": {
      "org/your-platform-package": {
        "runtime": "cpu"
      }
    }
  }
}

Variable precedence:

  1. Root app override (extra.platform-packages.<package-name>)
  2. Package default (extra.artifacts.vars)
  3. Built-in {version} (always provided by plugin)

Placeholder Behavior

  • {version} is built in and always available
  • Any {name} placeholder can be used
  • Unresolved placeholders cause artifact URL resolution to fail for that package
  • If override variables resolve to a URL that does not exist, the plugin retries with package default variables
  • On failure, Composer falls back to the package's original dist configuration

Platform Matching

The plugin matches the current machine against keys in artifacts:

  • OS-only keys: linux, darwin, windows, raspberrypi
  • OS + architecture keys: darwin-arm64, linux-x86_64, windows-32, windows-64, etc.
  • all as final fallback

More specific matches are preferred over generic ones.

Optional Helper: Generate URLs Command

platform:generate-urls is a helper to generate artifact URL entries from a template.

composer platform:generate-urls --dist-type=github --repo-path=vendor/repo --platforms=linux-x86_64 --platforms=darwin-arm64

You can also provide platforms as a comma-separated list:

composer platform:generate-urls --dist-type=github --repo-path=vendor/repo --platforms=linux-x86_64,darwin-arm64,windows-x86_64

Or with a custom URL template:

composer platform:generate-urls --dist-type=https://cdn.example.com/vendor/repo/release-{version}-{platform}.{ext} --platforms=linux-x86_64,darwin-arm64

Command options:

  • --platforms platform identifiers (repeat the flag or use comma-separated values)
  • --dist-type github, gitlab, huggingface, or custom template
  • --repo-path repository path for built-in templates
  • --extension force archive extension

The command writes generated URLs into extra.artifacts.

Testing

Run tests with:

composer test

The test suite includes:

  • unit tests for matching, templating, and generation logic
  • integration tests that run real composer install flows

License

MIT. See LICENSE.

codewithkyrian/platform-package-installer 适用场景与选型建议

codewithkyrian/platform-package-installer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 223.61k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2024 年 12 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 codewithkyrian/platform-package-installer 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-14