使用git和submodule,什么是一个好的文件夹结构? [英] Using git and submodule, what's a good folder structure?

查看:301
本文介绍了使用git和submodule,什么是一个好的文件夹结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对子模块使用git,并且我很难弄清楚如何组织我的文件。
我使用PHP开发,并使用单元测试。所以现在,我为每个模块使用这个组织:




  • src /

  • tests /



这似乎是个好主意,但问题是当我为项目执行git submodule add时,我会有这样的路径:
project / modules / News / src / index.php



src /文件夹确实存在问题。



我应该简单地将我的所有文件放在模块根目录下,并在源代码中混合使用测试/文件夹吗?对我来说听起来很糟糕。你在做什么?



编辑:由于autoload,src / Folder存在问题。我不应该把src放在我的所有课程名称中......

解决方案

您的文件夹布局与长时间无关因为自动加载器可以以某种方式找到你的文件。如果您使用PEAR约定将类名称映射到它们的源文件,则可以将src目录添加到包含路径或堆叠第二个自动装载器。然后你不必添加src到类名。

PEAR约定的替代方法是使用文件和类之间的静态映射。在可以在GitHub上为您自动生成这样的自动加载器的工具

静态自动加载器方法也用于 PHP项目向导。该工具将创建src和测试文件夹,其中包括 phpunit配置构建文件以将您的项目与Jenkins CI连接。这是一个方便的软件包。



至于包含子模块,请考虑将它们放到lib或ext文件夹中。在 GitHub上的phpdox项目中可找到这种外观的一个例子。请确保您也查看主引导文件,了解如何包含然后是各种自动加载器。

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/
  • tests/

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

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 ?

Edit: The src/ Folder is problematic because of the autoload. I should not have to put "src" in all my class name...

解决方案

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.

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.

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.

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.

这篇关于使用git和submodule,什么是一个好的文件夹结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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