开发者

Best way to share custom PHP code amongst projects

I'm developing a distributed environment, mostly in PHP. A lot of the projects that I have share some of the same code. For example my logging code (based on log4php but with some custom additions).

I can just copy-paste this code in every project, but naturally, if I change anything in it I need to re-paste it everywhere and 'hope' it doesn't change anythin开发者_StackOverflowg. Obviously not a good way.

Now, I was wondering: what is the best and simplest way of sharing this code? I'm hoping there is something as easy as making your own private PEAR-like channel? Do people do this for this use case? Or is there an ever easier way? I rather not start with inter-dependent repositories etc. If it matters though, I use Mercurial for versioning.

Thanks all.


Perhaps the best way (I am using too) is to host the common code in a versioning system such as Git or Mercurial or SVN and checkout this code in each related project. As long such a project does not have updates you can continue to work on your common code. In the case you want to touch a project again that utilizes the common code, you need to perform a source code update or pull. Then you update your project sources according to the changes of the common source base.


What about include_path PHP directive?

Just add include_path, for example /usr/share/php5/

and include your file like yourfile.php from each project


Use Git or Mercurial for that. In both of them, you can create sub-modules or sub-repositories.

http://kernel.org/pub/software/scm/git/docs/git-submodule.html

https://www.mercurial-scm.org/wiki/Subrepository

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜