Composer不会生成自动加载器信息(autoload_namespaces.php) [英] Composer does not generate autoloader information (autoload_namespaces.php)
问题描述
我无法通过composer正确安装项目.我有一个自己的自定义软件包(库),托管在一个非公共的git repo中(但集中化),由composer(包含用于测试我的软件包的composer.json的虚拟项目)获取.
I have trouble getting a project correctly installed through 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).
所以结构是这样的:
/test/project/composer.json
index.php
composer.json的内容:
Content of 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"
}
}
因此,当我在上面看到的包含测试项目和composer.json的文件夹中运行composer install"php composer.phar install"时-一切似乎都很好-但-自动加载器信息丢失-地图(数组")在"autoload_namespaces.php"中(生成的文件)保持为空.
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安装软件包时,并且该软件包(在我的情况下为foo/bar软件包)包含composer.json文件-该文件在安装过程中也会执行/处理,并且自动加载的信息取自此(程序包)composer.json文件.我对吗?还是我做错了什么?
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. Am i right? Or am i doing something wrong?
以下是软件包foo/bar中"composer.json"文件的内容:
Here is the content of the "composer.json" file from package foo/bar:
{
"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'
);
如果我手动插入此行'Foo'=> ...",则一切正常.但是我不知道为什么作曲家没有将此信息写入"autoload_namespaces.php"文件.
If i insert this line "'Foo' => ..." manually everything works fine. But i can't figure out why this information isn't written by composer to the "autoload_namespaces.php" file.
感谢您的帮助:)
推荐答案
如果尝试通过composer.json
的存储库"节点安装私有库/软件包,则还必须重新指定自动加载"节点显然.
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.
{
"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!
这篇关于Composer不会生成自动加载器信息(autoload_namespaces.php)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!