简体   繁体   English

Symfony 2捆绑有自己的composer.json

[英]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 installcomposer 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. 尽管您发布的内容包含许多所需的内容,但其中也包含一些不需要的值,例如,此处不需要classmapextra 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.jsonrequire部分。 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.

相关问题 Symfony 3包创建总是抛出“编辑composer.json文件” - Symfony 3 bundle creation always throws “Edit the composer.json file” Symfony2:是否可以在bundle中包含composer.json文件? - Symfony2: is it possible to have a composer.json file inside a bundle? 在 composer.json 中更新 symfony/symfony 版本 - Updating symfony/symfony version in composer.json 如何在Symfony 2.1中的composer.json中提供第三方库并在我们的包中访问库? - How to give third party libraries in composer.json in Symfony 2.1 and access library in our bundle? 将Doctrine 2.4与Symfony和composer.json一起使用 - Use Doctrine 2.4 with Symfony and composer.json 为什么Symfony Flex在composer.json的根目录级别添加自己的“ dev-develop”捆绑包? - Why does Symfony Flex adds own “dev-develop” bundles to root level in composer.json? Symfony REST:voryx / restgeneratorbundle安装失败,将./composer.json恢复为其原始内容 - Symfony REST: voryx/restgeneratorbundle Installation failed, reverting ./composer.json to its original content Composer.json需要我自己的私有软件包 - Composer.json require my own private package 当我自己的系统是供应商时,如何编写composer.json? - How to write composer.json while my own system is a vendor? 将Symfony2 2.3升级到2.4:更改composer.json - Upgrade Symfony2 2.3 to 2.4: Change composer.json
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM