Pregunta

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

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top