[英]PHP Composer is not adding namespace to autoload_psr4
(Before I begin, I have seen the two identical questions, both set the repository type to "package" which is NOT my issue here.) (在开始之前,我已经看到了两个相同的问题,都将存储库类型设置为“ package”,这不是我的问题。)
I have created my first composer packages and am trying to include them in another project. 我创建了我的第一个作曲家程序包,并试图将它们包含在另一个项目中。 However, the autoload settings I have created are not being added to the appropriate autoload file. 但是,我创建的自动加载设置未添加到适当的自动加载文件中。
Here is the dependencies composer.json: 这是依赖项composer.json:
{
"name": "company/authentication",
"description": "User authentication",
"require": {},
"require-dev": {
"phpunit/phpunit": "4.5.*"
},
"autoload": {
"psr-4": {
"Company\\Authentication\\": "src/"
}
}
}
And here is the parent composer.json where I am including the above file: 这是父composer.json,其中包含上述文件:
{
"config": {
"vendor-dir": "_framework/vendor",
"secure-http": false
},
"repositories": [
{
"type": "composer",
"url": "composer.<REDACTED>.com"
}
],
"require-dev": {
"phpunit/phpunit": "4.5.*",
"phpunit/dbunit": ">=1.2",
"phpunit/phpunit-selenium": ">=1.2"
},
"require": {
"company/authentication": "1.0.*"
}
}
And finally, this is the autogenerated autoload_psr4 file: 最后,这是自动生成的autoload_psr4文件:
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname(dirname($vendorDir));
return array(
'Symfony\\Component\\Yaml\\' => array($vendorDir . '/symfony/yaml'),
'Doctrine\\Instantiator\\' => array($vendorDir . '/doctrine/instantiator/src/Doctrine/Instantiator'),
);
And as it is asked below, I am not using Satis, instead I hand created a basic repository. 并按下面的要求,我没有使用Satis,而是手动创建了一个基本存储库。 This is my packages.json file for my repository: 这是我的存储库的packages.json文件:
{
"packages": {
"company/authentication": {
"1.0.0": {
"name": "company/authentication",
"version": "1.0.0",
"dist": {
"url": "http://composer.company.com/repo/authentication-1.0.0.zip",
"type": "zip"
}
}
},
etc...
And here is my composer.lock file: 这是我的composer.lock文件:
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "f67a284cbfcb2cf6ae3765266015710b",
"content-hash": "57c9067e1b3a3bb7fef45eeabb928ffd",
"packages": [
{
"name": "company/authentication",
"version": "1.0.0",
"dist": {
"type": "zip",
"url": "http://composer.company.com/repo/authentication-1.0.0.zip",
"reference": null,
"shasum": null
},
"type": "library"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}
You probably need to update your packages info. 您可能需要更新您的包裹信息。 You can do that, as the documentation suggest, with: 您可以按照文档中的建议执行以下操作:
php bin/satis build <configuration file> <build dir>
Example: 例:
php bin/satis build satis.json web/
You should do this every time you change something of yours composer.json
files. 每当您更改composer.json
文件中的某些内容时,都应该这样做。
Thanks for looking. 感谢您的光临。 I found the issue was that the dependencies and autoload settings need to be in the composer.json file of the library and in the packages.json file on the repository server. 我发现问题是依赖项和自动加载设置需要在库的composer.json文件中以及存储库服务器上的packages.json文件中。 It seems that the composer.json file contents of imported dependencies are ignored by composer. 似乎导入的依赖项的composer.json文件内容被composer忽略。
This completely confuses me - why does composer look at the server meta information to know what the dependencies are, instead of the composer.json file that is embedded with the code? 这完全让我感到困惑-为什么作曲家会查看服务器元信息以了解依赖项,而不是代码中嵌入的composer.json文件?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.