codezero/composer-preload-files 问题修复 & 功能扩展

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

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

codezero/composer-preload-files

Composer 安装命令:

composer require codezero/composer-preload-files

包简介

Composer plugin to autoload files before vendor files.

README 文档

README

GitHub release License Total Downloads

Autoload Your Files Before Vendor Files

This Composer plugin enables you to autoload files that you specify before any vendor files.

This package is based on the original funkjedi/composer-include-files by @funkjedi and its fork hopeseekr-contribs/composer-include-files by @hopeseekr. Because maintenance of these packages appears to be stalled, I decided to attempt and remake the package from scratch and fix any reported bugs in the process.

✅ Requirements

  • PHP >= 7.0
  • Composer ^2.3

📦 Install

Install this package with Composer:

composer require codezero/composer-preload-files

📘 Usage

Add the preload-files to your project's composer.json under the extra section:

"extra": {
    "preload-files": [
        "app/helpers.php"
    ]
},

The preload-files in the extra section will be loaded before the files in a standard autoload or autoload-dev section. This is true for your project, but also for any vendor package. Your project's preload files will always be loaded first.

🔌 Example Use Case

The best example use case is when you need to override a global helper function in a Laravel project. Those helper functions are declared in helper files that are loaded in the files array in the autoload section of composer.json:

"autoload": {
    "files": [
        "src/Illuminate/Collections/helpers.php",
        "src/Illuminate/Events/functions.php",
        "src/Illuminate/Foundation/helpers.php",
        "src/Illuminate/Support/helpers.php"
    ]
},

These functions are declared like this:

// helpers.php
if ( ! function_exists('route')) {
    function route($name, $parameters = [], $absolute = true)
    {
        return app('url')->route($name, $parameters, $absolute);
    }
}

If you add your own helper file to your project's autoload section to override such function, you will notice that Laravel's function is already loaded, and you can not redeclare it.

One way to solve this, is to manually require the helper file before Composer's autoload.php file. For Laravel, this means you need to require the file in your project's public/index.php file:

require __DIR__.'/../app/helpers.php';
require __DIR__.'/../vendor/autoload.php';

This works, but it is difficult, if not impossible to test (I did not find a way yet). If you are developing a package, it's also an extra step that users need take to install it.

Another solution is a package like this.

☕ Credits

🔒 Security

If you discover any security related issues, please e-mail me instead of using the issue tracker.

📑 Changelog

A complete list of all notable changes to this package can be found on the releases page.

📜 License

The MIT License (MIT). Please see License File for more information.

codezero/composer-preload-files 适用场景与选型建议

codezero/composer-preload-files 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 523.42k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 04 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「autoload」 「helpers」 「plugin」 「composer」 「require」 「files」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 codezero/composer-preload-files 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-02