使用git和符号链接的基于组件的web项目目录布局 [英] Component based web project directory layout with git and symlinks

查看:112
本文介绍了使用git和符号链接的基于组件的web项目目录布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



只有 www.example.com/webroot / 将暴露在apache中

  www.example.com/ 
webroot /
index.php
comp1 /
comp2 /
组件/
comp1 /
comp1.class.php
comp1.js
comp2 /
comp2.class.php
comp2.css
lib /
lib1 /
lib1.class.php

组件/ 和 lib / 目录只会在php路径中。



为了让css和js文件在webroot目录中可见,我计划使用符号链接。

  webroot / 
index.php
comp1 /
comp1.js(符号链接)
comp2 /
comp2.css(符号链接)

我试过以下原则:


  • 按组件和库进行布局,而不是通过文件类型,而不是通过public或non public,index.php是一个例外,这是为了更容易的开发

  • 暴露公共Web目录中的最小文件集,并使其他网站无法访问。将需要公开的组件和库文件symlinking到公共位置,但仍然镜像布局。库结构也可以在链接中生成的html代码中看到,这可能有助于开发。

  • git的用法应该是安全的并且总是可以工作的,按照某些过程添加符号链接到混帐,但之后检查出来或更改分支应安全和干净地处理



git将如何处理单个文件正确,有什么需要考虑的吗?



当涉及到图片时,我需要链接目录,如何使用git来处理它?<​​b>

 组件/ 
comp3 /
comp3.class.php
img /
img1.jpg
img2.jpg
img3 .jpg

它们应该在这里链接:

  webroot / 
comp3 /
img /(符号链接?)

如果使用符号链接有缺点,我可能会直接将图像移动到webroot / tree,这会破坏第三个原则(git实用性)。



所以这是一个混帐和符号链接问题。但我有兴趣听到有关php布局的评论,也许你想使用评论功能。

一旦你需要在其他地方重新使用一些文件,那么你应该开始考虑 组件 或(在git中) submodules



代替管理 webroot ,和 comp lib 在同一个repo中(这是SVN或集中化的方式用于CVCS ),您可以定义:




  • n repos,每个组件需要重用一个(所以' img '会成为Git例如,在 webroot 中重新使用repo作为子模块)

  • 用于引用所需子模块的确切修订版本的主项目。 / li>


这是符号链接子模块的优点之一:您引用一个完全修订版,并且该组件具有一些自己的演变,你不会立即看到它们(直到你更新你的子模块)。
使用符号链接,你可以看到该链接另一端的文件集。


I am planning my directory structure for a linux/apache/php web project like this:

Only www.example.com/webroot/ will be exposed in apache

www.example.com/
  webroot/
    index.php
    comp1/
    comp2/
  component/
    comp1/
      comp1.class.php
      comp1.js
    comp2/
      comp2.class.php
      comp2.css
  lib/
    lib1/
      lib1.class.php

the component/ and lib/ directory will only be in the php path.

To make the css and js files visible in the webroot directory I am planning to use symlinks.

  webroot/
    index.php
    comp1/
      comp1.js (symlinked)
    comp2/
      comp2.css (symlinked)

I tried following these principles:

  • layout by components and libraries, not by file type and not by "public' or 'non public', index.php is an exception. This is for easier development.
  • expose onle the minimal set of files in a public web directory and make everything else unaccesable to the web. Symlinking files that need to be public for the components and libs to a public location, but still mirroring the layout. So the component and library structure is also visible in the resulting html code in the links, which might help development.
  • git usage should be safe and always work. it would be ok to follow some procedure to add a symlink to git, but after that checking them out or changing branches should be handled safely and clean

How will git handle the symlinking of the single files correctly, is there something to consider?

When it comes to images I will need to link directories, how to handle that with git?

  component/
    comp3/
      comp3.class.php
      img/
        img1.jpg
        img2.jpg
        img3.jpg

They should be linked here:

  webroot/
    comp3/
      img/ (symlinked ?)

If using symlinks for that has disadvantages maybe I could move images to the webroot/ tree directly, which would break the first principle for the third (git practicability).

So this is a git and symlink question. But I would be interested to hear comments about the php layout, maybe you want to use the comment function for this.

解决方案

As soon as you need to reuse some set of files elsewhere, that's when you should start thinking in term of components or (in git) submodules

Instead of managing webroot, and comp, and lib within the same repo (which is the SVN or the "Centralized way" for CVCS), you define:

  • n repos, one per component you need to reuse (so 'img' would be a Git repo reused as a submodule within webroot, for instance)
  • a main project for referencing the exact revision of those submodules you need.

That is one of advantages of submodules of symlink: you reference one exact revision, and if that component has some evolutions of its own, you don't see them immediately (not until you update your submodule anyway).
With a symlink, you see whatever state is the set of files at the other end of that link.

这篇关于使用git和符号链接的基于组件的web项目目录布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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