duxthefux / composer-include-files
包含文件优先级高于自动加载文件。
2.0.0
2020-05-18 09:02 UTC
Requires
- composer-plugin-api: ^2.0
This package is auto-updated.
Last update: 2024-09-18 18:43:53 UTC
README
当使用Composer自动加载器时,如果您需要包含项目文件,而这些文件在您的依赖项自动加载之前,那么您将无法实现。但现在可以了!
安装
composer require funkjedi/composer-include-files
用法
只需使用 "include_files"
添加您需要包含的文件,它们将在您的依赖项包含的任何文件之前被包含。
// composer.json (project) { "extra": { "include_files": [ "/path/to/file/you/want/to/include", "/path/to/another/file/you/want/to/include" ] }, }
特定用例
这是一个需要此功能的良好例子,比如在覆盖Laravel提供的辅助函数时。
过去,仅仅修改 bootstrap/autoload.php
以包含辅助函数就足够了。然而,PHPUnit的新版本在执行PHPUnit引导文件之前包含了Composer自动加载器。因此,这种方法已不再可行,因为它会在包含引导文件时触发致命错误。
但现在,我们可以使用 Composer - 包含文件插件 来按必要的顺序包含文件。
// composer.json (project) { "require": { "laravel/framework": "^5.2", "funkjedi/composer-include-files": "^1.0", }, "extra": { "include_files": [ "app/helpers.php" ] }, }