在项目之间共享自定义PHP代码的最佳方法 [英] Best way to share custom PHP code amongst projects

查看:69
本文介绍了在项目之间共享自定义PHP代码的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个分布式环境,主要是使用PHP。
我拥有的许多项目都共享一些相同的代码。例如,我的日志记录代码(基于log4php,但带有一些自定义添加项)。

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 anything. Obviously not a good way.

现在,我想知道:共享此代码的最佳和最简单的方法是什么?
我希望有一个像创建自己的类似PEAR的私人频道一样容易的事情吗?人们是否在此用例中这样做?还是有更简单的方法?我宁愿不从相互依赖的存储库等开始。如果有关系,我将使用Mercurial进行版本控制。

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.

谢谢。

推荐答案

也许(我也在使用)最好的方法是将通用代码托管在Git或Mercurial或SVN等版本控制系统中,并在每个相关项目中检出此代码。只要此类项目没有更新,您就可以继续使用通用代码。如果您想再次触摸使用通用代码的项目,则需要执行源代码更新或提取。然后,根据公共源库的更改来更新项目源。

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.

这篇关于在项目之间共享自定义PHP代码的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆