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.

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

报告相同问题?

悬赏问题

  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错