使用 git 和子模块,什么是好的文件夹结构?
我将 git 与子模块一起使用,我很难弄清楚如何组织我的文件.我用 PHP 开发,并使用单元测试.所以现在,我为每个模块使用这个组织:
I use git with submodules, and I've hard time to figure out how to organize my files. I develop in PHP, and use unit testing. So right now, I use this organization for each module:
- src/
- 测试/
这似乎是一个绝妙的主意,但问题是当我对项目执行git submodule add"时,我将拥有这条路径:项目/模块/新闻/src/index.php
That seems like a brilliant idea, but the problem is that when I do a "git submodule add" to a project, I'll have that path: project/modules/News/src/index.php
src/文件夹真的有问题.
The src/ folder is really problematic.
我是否应该简单地将我的所有文件放在模块根目录中,并在源代码中混合一个测试/文件夹?对我来说这听起来很糟糕.你在做什么?
Should I simply put all my file in the module root, and have a tests/ folder mixed in the source ? To me that sound bad. What are you doing ?
src/文件夹由于自动加载而有问题.我不应该将src"放在我所有的班级名称中......
The src/ Folder is problematic because of the autoload. I should not have to put "src" in all my class name...
推荐答案
只要自动加载器能以某种方式找到您的文件,您的文件夹布局就几乎无关紧要.如果您使用 PEAR 约定将类名映射到其源文件,则可以将 src 目录添加到包含路径或堆叠第二个自动加载器.然后您不必将 src 添加到类名中.
Your folder layout is mostly irrelevant as long as the autoloader can find your files somehow. If you are using PEAR convention for mapping class names to their source files, you can add the src directory to the include path or stack a second autoloader. Then you dont have to add src to the class names.
PEAR 约定的替代方案是在文件和类之间使用静态映射.GitHub 上有一个工具可以自动为你生成这样的自动加载器.
The alternative to PEAR convention would be to use a static mapping between files and classes. There is a tool that can automatically generate such an autoloader for you at GitHub.
PHP 项目向导中也使用了静态自动加载器方法.该工具将创建 src 和测试文件夹,包括 您的 phpunit 配置以及 构建文件以将您的项目与 Jenkins CI 连接起来.这是一个方便的包.
The static autoloader approach is also used in PHP Project Wizard. That tool will create src and tests folders, including your phpunit config and the build file to connect your project with Jenkins CI. It's a convenient package.
至于包含子模块,请考虑将它们放入 lib 或 ext 文件夹.可以在 GitHub 上的 phpdox 项目中找到有关外观的示例.确保您还查看 主引导文件 以了解如何包含然后是各种自动装载机.
As for including submodules, consider putting them into a lib or ext folder. An example of how that looks can be found in the phpdox project at GitHub. Make sure you also look at the main bootstrap file to see how to include the various autoloaders then.
相关文章