dongshi1188 2014-05-15 07:05
浏览 421
已采纳

使用Composer,可以在多个项目之间共享依赖项吗?

First of all, I'm a complete newbie to Composer. I've been trying it out since it's a sounds awesome and mainly because Zend Framework 2 uses it.

Zend Framework 2 is actually also the reason for this thread.

It get the basics of Composer. But with my current server setup I have a request, which I can't seem to figure out if possible.

Let me explain.

I have multiple Zend Framework 2 projects:

  • /home/morten/sites/Project-1/
  • /home/morten/sites/Project-2/
  • /home/morten/sites/Project-3/

All of these projects should be running ZF2. When running composer in each project - each of them get their own separate download of the ZF2 Library files. Which is a bit redundant with my setup.

I have a complete and up-to-date download of ZF2 Library located at: /var/www/shared/Zend/

And my php.ini has that path added to PHP's include_path, so the whole ZF2 library is available for all the three projects.

IS IT POSSIBLE to make Composer use in it's setup. Because if I try to change stuff and try things out in the composer files, then it just re-downloads Zend because it's a required component for other modules.

Can this be done? And if yes, how can I do it?

Hope I have explained myself good enough for you guys to understand what I'm trying to do and want :)

Thanks a lot in advance!

Regards, Morten

  • 写回答

1条回答 默认 最新

  • doushan9415 2014-05-15 07:52
    关注

    You might be able to have one composer.json file stored in /var/www/shared/Zend, where you would put your dependencies and use Composer do manage them. Then all projects could include the same autoloader.

    However, I wouldn't recommend that approach:

    • Your project's dependencies (composer.json) should be stored with your project. If you want to install your project somewhere else (for instance if you want to move one project to another server), you are missing the composer.json to install the required dependencies.
    • It will not be possible to update the dependencies of one project, without updating the dependencies of all other projects. If you want to introduce a new feature in Project 1, which requires a new version of a certain dependency, all other projects will get this new version as well - which might introduce backward compatibility breaks if an older feature that Project 2 relies on, is no longer supported. Since you can only have one version of each dependency, it is not possible for two projects to have different versions of the same dependency.

    This approach might be useful if all projects will have the exact same functionality and code, but in that case you should probably merge them into one project.

    In all other cases, I would suggest to use Composer the way it's supposed to be used: give all projects their own composer.json file and let Composer download the dependencies per project, in each project's vendor directory. The downside is that it'll cost you a little more disk space, but you'll get a lot of flexibility for it in return.

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

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测