[英]Composer does not generate autoloader information (autoload_namespaces.php)
I have trouble getting a project correctly installed through composer.我无法通过 Composer 正确安装项目。 I have a own custom package (library) hosted in a non public git repo (but centralized) which is fetched by composer (dummy project containing a composer.json just for testing my package).我有一个自己的自定义包(库)托管在一个非公共 git repo(但集中式)中,它由 composer 获取(包含 composer.json 的虚拟项目,仅用于测试我的包)。
So the structure is like that:所以结构是这样的:
/test/project/composer.json
index.php
Content of composer.json: composer.json 的内容:
{
"name": "vendor/test",
"description": "Test-description",
"authors": [{
"name": "Benjamin Carl",
"email": "email@testdomain.com",
"homepage": "http://www.testdomain.com",
"role": "Developer"
}],
"keywords": [
"foo",
"bar"
],
"homepage" : "http://www.testdomain.com/",
"license" : [
"The BSD License"
],
"repositories": [{
"type": "package",
"package": {
"name": "foo/bar",
"version": "0.0.1",
"source": {
"url": "git@git.testdomain.local:benjamin.carl/bar.git",
"type": "git",
"reference": "master"
}
}
}],
"require": {
"foo/bar": "0.0.1"
}
}
So when i run the composer install "php composer.phar install" within the folder containing the test-project and the composer.json you see above - everything seems to be fine - but - the autoloader information is missing - the map (array) in "autoload_namespaces.php" (files getting generated) keeps empty.因此,当我在包含测试项目和上面看到的 composer.json 的文件夹中运行 composer install "php composer.phar install" 时 - 一切似乎都很好 - 但是 - 缺少自动加载器信息 - 地图(数组)在“autoload_namespaces.php”(生成的文件)中保持为空。
I assumed that when i install a package with composer and the package (in my case the package foo/bar) contains a composer.json file - this file is also executed/processed during installation and the information for autoloading is taken from this (package) composer.json file.我假设当我用 composer 安装一个包时,这个包(在我的例子中是包 foo/bar)包含一个 composer.json 文件 - 这个文件也在安装过程中被执行/处理,并且自动加载的信息是从这个(包) composer.json 文件。 Am i right?我对吗? Or am i doing something wrong?还是我做错了什么?
Here is the content of the "composer.json" file from package foo/bar:这是 foo/bar 包中“composer.json”文件的内容:
{
"name": "foo/bar",
"description": "foo - the project for all bars out there.",
"authors": [{
"name": "Benjamin Carl",
"email": "email@testdomain.com",
"homepage": "http://www.testdomain.com",
"role": "Developer"
}],
"keywords": [
"php",
"foo",
"bar",
"baz"
],
"homepage": "http://testdomain.com/",
"license": [
"The BSD License"
],
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-0": {
"Foo": "Framework/"
}
},
"include-path": ["Framework/"],
"support": {
"email": "email@testdomain.com",
"issues": "https://testdomain.com/issues",
"wiki": "https://testdomain.com/wiki"
},
"repositories": [{
"type": "vcs",
"url": "https://git.testdomain.local/test/bar.git"
}]
}
As the result of the configuration(s) above i want the autoloading information like this:作为上述配置的结果,我想要这样的自动加载信息:
$data = array(
'Foo' => $vendorDir . '/foo/bar/Framework'
);
If i insert this line "'Foo' => ..." manually everything works fine.如果我手动插入这一行“'Foo' => ...”,一切正常。 But i can't figure out why this information isn't written by composer to the "autoload_namespaces.php" file.但我不明白为什么 Composer 没有将这些信息写入“autoload_namespaces.php”文件。
Thanks for any help :)谢谢你的帮助 :)
If you try to install a private library/package via the "repositories" node of composer.json
you have to re-specify the "autoload" node as well apparently.如果您尝试通过composer.json
的“存储库”节点安装私有库/包,您显然也必须重新指定“自动加载”节点。
{
"repositories": [{
"type": "package",
"package": {
"name": "foo/bar",
"version": "0.0.1",
"source": {
"url": "git@git.testdomain.local:benjamin.carl/bar.git",
"type": "git",
"reference": "master"
},
"autoload": {
"psr-0": {
"Foo": "Framework/"
}
}
}]
}
I just spent a couple of hours figuring this out.我只是花了几个小时来弄清楚这一点。 Good job, Composer!干得好,作曲家!
Your package foo/bar
has declared an include-path
.你的包foo/bar
已经声明了一个include-path
。 This feature is deprecated and should only be used to support legacy code that cannot be autoloaded, according to the documentation (see http://getcomposer.org/doc/04-schema.md#include-path ).根据文档(请参阅http://getcomposer.org/doc/04-schema.md#include-path ),此功能已弃用,仅应用于支持无法自动加载的遗留代码。
I assume it is the reason your package does not get added to autoloading because it could also be loaded via include path (which is a bad thing because of too much performance impact - avoid it at all cost).我认为这是您的包没有被添加到自动加载的原因,因为它也可以通过包含路径加载(这是一件坏事,因为性能影响太大 - 不惜一切代价避免它)。
Zacharydanger solution works if you require the packages without changing the default install path (which is the vendor
folder).如果您需要软件包而不更改默认安装路径(即vendor
文件夹),则 Zacharydanger 解决方案有效。
If you use composer/installer-paths
and install your package outside of the vendor folder, you need to set the autoload path accordingly.如果您使用composer/installer-paths
并在供应商文件夹之外安装您的包,您需要相应地设置自动加载路径。
{
"repositories": [{
"type": "package",
"package": {
"name": "foo/bar",
"version": "0.0.1",
"source": {
"url": "git@git.testdomain.local:benjamin.carl/bar.git",
"type": "git",
"reference": "master"
},
"extra": {
"installer-paths": {
"core/{$name}": [
"type:git-package"
]
}
},
"autoload": {
"psr-0": {
"Foo": "core/Framework/"
}
}
}]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.