dsvs50005 2013-07-03 13:35
浏览 79
已采纳

Symfony2.3 - 如何添加自定义供应商

I have a Symfony 2.3 project and I would like to use a custom vendor. I know that on Symfony versions 2.1 and 2.2, you can declare vendors in the deps file.

But how can I declare a custom vendor in Symfony 2.3 project? There is a composer.json file, but I don't really understand how it works.

EDIT:
The custom vendor's code is located on github.

  • 写回答

1条回答 默认 最新

  • douting1871 2013-07-03 14:17
    关注

    composer.json manages dependencies through the composer tool (which you should have installed). It behaves similarly to npm if you have used that at all.

    You can include a custom vendor in a couple of ways - although for the custom vendor code to be (auto)loaded & picked up by composer it will need to have a composer.json file.

    Packagist

    If the custom vendor has successfully submitted their to packagist then you life is easy, you can search for it and take note of the name (in the <vendor>/<package> format.

    Open up your composer.json file and at the end of the "require": {} statement add your vendor. For example if our package was called peterjmit/awesome-package

    // ...
    "require": {
      // ...
      "peterjmit/awesome-package": "*"
    },
    // ...
    

    You can replace the * with a version number if you wish. Once you have done that, you can run the composer update command to pull in your new package. If you only want to update the new package you can use composer update peterjmit/awesome-package.

    Thanks to the composer autoloader, and the PSR-0 standard, classes from the package are auto-loaded so there is no other "plumbing" for you to do.

    VCS repository

    If the custom vendor is not on packagist, but does have a composer.json file then you can specify a custom repository to composer. You need to have the same require statement as before, but you need to add a new statement to composer.json

    // ...
    "require": {
      // ...
      "peterjmit/awesome-package": "*"
    },
    "repositories": [
      {
        "type": "vcs",
        "url": "git@bitbucket.org:peterjmit/awesome-package.git"
      },
      // .. etc.
    

    If the package does not have a composer.json then you can always fork it and add your own. But if the code does not conform to PSR-0 then you will have to sort out your own auto-loading strategy for the package.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?