gpt4 book ai didi

PHP+Composer : Adding files to autload_static. php加载包

转载 作者:行者123 更新时间:2023-12-03 23:32:23 24 4
gpt4 key购买 nike

我在通过 composer 加载我需要的包时遇到了问题composer 需要包

PHP(5.6 版)表示无法识别此包。

在查看脚本时,我在 autoload_real.php 中找到了这些行:

$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION');
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';

call_user_func(\Composer\Autoload\ComposerStaticInitb5ab90658915f56241dbbea020198264::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}

$map = require __DIR__ . '/autoload_psr4.php';
echo "<br>";
var_dump($map);
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}

$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
}

我的包在 autoload_psr4.php 文件中列出,并在 packages 数组中返回,但代码进入 if 子句($useStaticLoader 为真)和 autoload_static .php 我的包没有列出。

$useStaticLoader 设置为 false 时,else 子句按预期加载我的包。

我要补充一点,我正在安装的包将自己声明为 psr4 包。

静态标志是什么意思,如何让我的包列在 autoload_static.php 数组中?

最佳答案

Allow optionally disabling the static autoloader

The static autoloader presents a problem for environments where pre-PHP 5.6 syntax compatibility is required. Many projects have automated CI that runs a linter across all files in the repository to prevent developers from accidentally introdcing incompatible syntax. And while the static autoloader properly guards itself on lower PHP versions, it will still trip up linters. Given the number of bugs filed about this, it appears to be a common setup: #5255, #5316, #5324, and #5407.

This adds a --no-static option to the dump-autoload command, which will disable the static autoloader by updating autoload_real.php to not look for the file, and removes autoload_static.php if it exists.

您也可以使用带有 install / update--optimize-autoloader 标志来避免这种情况.

附注:我在 php 5.6 上也遇到了同样的问题,请检查你的路径和命名空间两次!

关于PHP+Composer : Adding files to autload_static. php加载包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38168115/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com