[英]Symfony 2 bundle with its own composer.json
I am creating a new Symfony 2 bundle which I am aiming to open source. 我正在创建一个新的Symfony 2软件包,旨在将其开源。 It lives in
/src/crmpicco/ChargebeeBundle
. 它位于
/src/crmpicco/ChargebeeBundle
。
Inside that directory I have a composer.json
, which looks like this: 在该目录中,我有一个
composer.json
,看起来像这样:
{
"name": "crmpicco/ChargebeeBundle",
"type": "library",
"description": "A Symfony 2 bundle which provides an easy way to handle billing and subscriptions.",
"keywords": [
"crmpicco",
"Chargebee",
"Symfony",
"Subscription"
],
"license": "MIT",
"authors": [
{
"name": "CRMPicco",
"email": "picco@crmpicco.co.uk",
"homepage": "http://www.crmpicco.co.uk",
"role": "Analyst Developer"
}
],
"require": {
"chargebee/chargebee-php": "^2.0"
},
"autoload": {
"psr-0": {
"": "src/",
"SymfonyStandard": "app/"
},
"classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
},
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"symfony-assets-install": "relative"
}
}
The dependency the bundle requires is chargebee/chargebee-php
, however when I do a composer install
or composer update --prefer-dist
from the main Symfony project directory it does not recognise this composer.json or make any attempt to pull down that dependency. 捆绑软件需要的依赖关系是
chargebee/chargebee-php
,但是当我从Symfony项目主目录执行composer install
或composer update --prefer-dist
,它无法识别此composer.json或进行任何尝试来降低该依赖关系。
Do I have my composer.json in the correct location and do I have my file structure set out correctly? 我的composer.json是否位于正确的位置,文件结构是否正确设置?
Dependencies for the code in src
are defined in the project's root composer.json
. src
中代码的依赖关系在项目的根composer.json
中定义。 The one in your /src/crmpicco/ChargebeeBundle
is ignored. /src/crmpicco/ChargebeeBundle
被忽略。
If you want to release previously private code as shared package, you can do the following: 如果要将以前的私有代码作为共享程序包发布,则可以执行以下操作:
First, read the official best practices for reusable bundles . 首先,请阅读可重复使用捆绑软件的官方最佳做法 。 This will help to structure your project in a way that allows other developers to work with it.
这将有助于以允许其他开发人员使用它的方式来构建项目。
Then, clean up the composer.json
. 然后,清理
composer.json
。 Although the one you've posted contains much of what is needed, it also has some unneeded values, eg classmap
and extra
are not needed here. 尽管您发布的内容包含许多所需的内容,但其中也包含一些不需要的值,例如,此处不需要
classmap
和extra
。 You might want to try this one (feel free to add author, keywords, etc.): 您可能想尝试一下(随意添加作者,关键字等):
{
"name": "crmpicco/ChargebeeBundle",
"type": "symfony-bundle",
"require": {
"chargebee/chargebee-php": "^2.0"
},
"autoload": {
"psr-4": {
"Crmpicco\\ChargebeeBundle\\": ""
}
},
"license": "MIT"
}
Then you must decide if you want to serve the bundle from a private repo or from something like Github and want it to be registered in Packagist. 然后,您必须决定是要从私人仓库还是从类似Github的服务中分发捆绑包,并希望将其注册到Packagist中。
If you want it in a private repo, you must edit your global composer.json
and add the following section: 如果要在私人仓库中使用它,则必须编辑全局
composer.json
并添加以下部分:
"repositories": [
{
"type": "vcs",
"url": "ssh://git@yourgitserver.example.com/path.to.repo.git"
}
]
If you want to make it an official Packagist package, register an account there and follow the instructions to add your package. 如果要使其成为正式的Packagist软件包,请在此处注册一个帐户,然后按照说明添加您的软件包。 (Don't forget to set up the update hook.)
(不要忘记设置更新挂钩。)
In both cases you will now have to add the package name to the require
section of your root composer.json
. 在这两种情况下,您现在都必须将包名称添加到root
composer.json
的require
部分。 As long as you haven't tagged releases in your package, you must add dev-master
as required version and also add the line "minimum-stability" : "dev"
to the root composer.json
. 只要您的软件包中没有标记发行版,就必须将
dev-master
添加为必需版本,并在根composer.json
添加"minimum-stability" : "dev"
行。
Now, delete the code from /src/crmpicco/ChargebeeBundle
(or move it outside of the Symfony project) and run composer update --prefer-source
. 现在,从
/src/crmpicco/ChargebeeBundle
删除代码(或将其移至Symfony项目之外),然后运行composer update --prefer-source
。 You should now find the bundle installed under vendor. 现在,您应该在供应商下找到安装的捆绑软件。
You may also realize that Composer updates all your Symfony packages to some xx-dev
version, which is due to the "miminum-stability" setting. 您可能还意识到,由于“最小稳定性”设置,Composer将所有Symfony软件包更新为某些
xx-dev
版本。 Let it be; 随它去; you can remove the "miminum-stability" line after the first successful run and then
composer update
again. 您可以在第一次成功运行后删除“最小稳定度”行,然后再次
composer update
。 It will then downgrade the Symfony dev packages again, but leave your bundle alone. 然后它将再次降级Symfony开发软件包,但请不要管它。 This is a quite quirky approach, but I haven't found a better one yet.
这是一种非常古怪的方法,但是我还没有找到更好的方法。 (Maybe somebody else knows a better way to handle this.)
(也许其他人知道更好的方法来解决这个问题。)
If you run into problems installing, read the output from Composer carefully and follow the instructions. 如果安装时遇到问题,请仔细阅读Composer的输出并按照说明进行操作。 For example, you might have a mismatch between the package name in the bundle's
composer.json
and the require
line. 例如,您可能在软件包的
composer.json
的软件包名称与require
行之间不匹配。 Or Composer might complain about unresolvable dependencies, which you need to fix. 否则Composer可能会抱怨无法解决的依赖关系,您需要修复这些依赖关系。
Good luck! 祝好运! You may still run into other problems, but I would recommend that you post them as separate SO questions – unless they are trivial, in which case you're welcome to post them as comments, and I'll try to answer them and/or update this post accordingly.
您可能仍然会遇到其他问题,但是我建议您将它们作为单独的SO问题发布-除非它们很琐碎,否则在这种情况下,欢迎您将其发布为评论,我会尽力回答和/或相应地更新此帖子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.