且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

作曲家自动加载开发不起作用

更新时间:2023-11-17 10:15:52

我的猜测是你正在显示 vendor / namespace 包的 composer.json 。如果是这种情况:



查看文档。它说:autoload-dev(仅限根)。根仅意味着它仅适用于根包。当你包含这个包时,所显示的 composer.json 文件不是根包,而 autoload-dev 部分是因此被忽略。


The file autoload_psr4.php not contains the namespace from "autoload-dev" section only from "autoload" section.

When my composer.json reads

"autoload": {
    "psr-4": {
        "Namespace\\": "src/"
    }
},
"autoload-dev": {
    "prs-4": {
        "Namespace\\Tests\\": "tests/"
    }
}

And I run

composer require vendor/namespace 1.0-dev

My /vendor/composer/autoload_prs4.php file appears as

// autoload_psr4.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    'Namespace\\' => array($baseDir . '/src'),
);

Thanks!

My guess is that you're showing the composer.json of vendor/namespace package. If that's the case:

Take a look at the docs. It says: "autoload-dev (root only)". root only means it only applies to the root package. As you included the package, the shown composer.json file is not the root package and the autoload-dev section is thus ignored.