使用composer,gulp和Travis的PHP网站的目录结构

Viv*_*sas 18 php build-process composer-php gulp

我正在试图找出一个php网站的目录结构.

该网站将使用:

  • 一个非常基本的php MVC框架(即MinimalMVC,但我正在寻找一个通用的解决方案,所以框架可能会被忽略)
  • composer来管理PHP依赖项
  • SCSS用于造型
  • gulp用于编译SCSS(用于开发构建),还可以缩小和连接JS和CSS输出以及缩小图像等(仅用于部署构建)
  • 特拉维斯CI为CI的东西

所以经过大量的思考和规划,并查看了我提出的各种目录结构的问题,我仍然找不到符合我标准的东西:

  • gulp deploy应该能够生成一个部署文件夹,当放入/var/www/html/Apache服务器上的目录时,应该是Just Work TM

    注意:MinimalMVC(以及CodeIgniter和其他类似的框架)需要index.php在根目录中使用它们的文件,appsys在同一目录中使用和文件夹

  • 由于PHP从未真正由构建过程处理,因此如果不必要地将src/**/*.php文件复制到build/**/*.php可避免的内容中,那将是很好的.基本上,PHP部分不会保持吞咽,我更喜欢它不受gulp的影响.

现在,我的想法有点乱,因为我一直在考虑这个问题,所以请原谅我这个问题有点乱,但基本的问题是,目录结构应该怎么样?

一个主意:

.
|-- composer.json
|-- gulpfile.js
|-- package.json
|-- src
|   |-- app
|   |   |-- controllers
|   |   |-- models
|   |   `-- <other_framework_stuff>
|   |-- assets
|   |   |-- css
|   |   |-- img
|   |   |-- js
|   |   `-- raw
|   |       `-- scss
|   |-- index.php
|   `-- sys
|       `-- <framework_stuff>
|-- test
`-- vendor
    `-- <composer_stuff>
Run Code Online (Sandbox Code Playgroud)

在此结构中,开发人员只能在/src目录中工作.SCSS从编译/src/assets/raw/scss/src/assets/css.这样,PHP仍然从构建过程中删除.当尝试生成deploy目录时,src文件夹被复制,/src/assets/raw/(所以没有/build/assets/raw)目录不存在,并且生成/部署准备好的CSS,JS和图像被找到/build/assets/.

这个解决方案的第一个问题是奇怪的src/assets/raw目录,这看起来很难看.第二个问题是/vendor目录.这意味着php从外部src引用了一些东西.因此,如果/src/index.php要照顾它,它将包括../vendor/autoload.php.那意味着相同的代码被复制到/build/index.php.然后/build/将不会只是拖放到运行/var/www/html,除非vendor是在/var/www刚刚似乎不可思议.

我想到了很多其他的东西,但所有这些看起来都很丑陋.为了避免这个问题太长,我会停在这里.

请帮忙.如果我只是把vendor/src/使用vendor-dircomposer.json?(我知道,eww.)我应该使用什么样的目录结构?

Amo*_*Amo 15

我同意上面Korri的评论,因为你可以从现有框架中获取灵感.

就个人而言,这种目录结构对我来说是正确的.

.
|-- composer.json
|-- gulpfile.js
|-- package.json
|-- changelog.md
|-- readme.md
|-- /src (This is the API code that *I'm* responsible for, and that I *own*.).
|   |-- /app
|   |   |-- /controllers
|   |   |-- /models
|   |   `-- <other_framework_stuff>
|   /public (Keeping this outside of the src dir, means that you can give this to your front-end devs without needing to have the entire codebase).
|   |   |-- /styles
|   |   |-- /images
|   |   |-- /js
|   /config (Put all configuration files outside of the src scope, so you can keep it outside of source control)
|   /build (CI build related configuration)
|   |   |--phpcs.xml
|   |   |--phpdocx.xml
|-- /tests (separating out your tests in this way can help you run tests separately, more easily)
|   |   |--acceptance
|   |   |--integration
|   |   |--unit
|-- /vendor (Depenedencies installed via Composer)
Run Code Online (Sandbox Code Playgroud)

真的,没有社区驱动正确回答你的问题.正确的答案是特定于您的业务,团队,你的工作,而项目本身.

我从来没有把/vendor目录内的/src目录-因为你不拥有它.您不对项目依赖项中代码的更改负责,因此应将其留在项目墙外的自己的范围内.

使用PSR-4自动加载,对于您的目录结构来说真的无关紧要,它可以随时轻松更改,而不会对您的代码产生任何影响.所以,实验,看看有什么感觉适合你.