project-structure.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <!-- EN-Revision: 18656 -->
  4. <appendix id="project-structure">
  5. <title>Zend Framework MVC アプリケーションのために推奨されるプロジェクト構造</title>
  6. <sect1 id="project-structure.overview">
  7. <title>概要</title>
  8. <para>
  9. たくさんの開発者が、比較的柔軟な環境でZend Frameworkプロジェクトのための
  10. 最善のプロジェクト構造のガイダンスを望みます。
  11. 「柔軟な」環境とは、
  12. それらのアプリケーションを実行し、かつ安全にするための
  13. 最も理想的なプロジェクト構造を達成するために、
  14. 必要に応じてそれらのファイルシステムとウェブサーバ構成を開発者が操作できる
  15. 環境です。
  16. デフォルトのプロジェクト構造では、
  17. それらの配置で開発者がそのような柔軟性を持つと仮定します。
  18. </para>
  19. <para>
  20. 以下のディレクトリ構造は、
  21. 複雑なプロジェクトのために最大限に拡張可能に設計されています。
  22. その一方で、プロジェクトのためのフォルダとファイルの単純なサブセットを
  23. より単純な必要条件で提示します。
  24. この構造も、モジュラー及び非モジュラー両方のZend Frameworkアプリケーションのために、
  25. 変更なしで動作します。
  26. <filename>.htaccess</filename>ファイルは、
  27. この付録に含まれる<link linkend="project-structure.rewrite">リライト構成ガイド</link>
  28. で定めるウェブサーバでも、<acronym>URL</acronym>リライト機能を必要とします。
  29. </para>
  30. <para>
  31. このプロジェクト構造で、可能性があるすべてのZend Frameworkプロジェクト条件を
  32. サポートすることは意図していません。
  33. <classname>Zend_Tool</classname>によって使われるデフォルトのプロジェクト・プロフィールは、
  34. このプロジェクト構造を反映します。
  35. しかし、この構造でサポートされない必要条件を持つアプリケーションでは、
  36. カスタム・プロジェクト・プロフィールを使わなければなりません。
  37. </para>
  38. </sect1>
  39. <sect1 id="project-structure.project">
  40. <title>推奨されるプロジェクト・ディレクトリ構造</title>
  41. <programlisting language="txt"><![CDATA[
  42. <project name>/
  43. application/
  44. configs/
  45. application.ini
  46. controllers/
  47. helpers/
  48. forms/
  49. layouts/
  50. filters/
  51. helpers/
  52. scripts/
  53. models/
  54. modules/
  55. services/
  56. views/
  57. filters/
  58. helpers/
  59. scripts/
  60. Bootstrap.php
  61. data/
  62. cache/
  63. indexes/
  64. locales/
  65. logs/
  66. sessions/
  67. uploads/
  68. docs/
  69. library/
  70. public/
  71. css/
  72. images/
  73. js/
  74. .htaccess
  75. index.php
  76. scripts/
  77. jobs/
  78. build/
  79. temp/
  80. tests/
  81. ]]></programlisting>
  82. <para>
  83. 以下では、一覧に記載されたディレクトリ毎に利用例を記述します。
  84. </para>
  85. <itemizedlist>
  86. <listitem>
  87. <para>
  88. <emphasis><filename>application/</filename></emphasis>:
  89. このディレクトリは、アプリケーションを含みます。
  90. 構成や利用されるサービス、及びブートストラップ・ファイルと同様に、
  91. <acronym>MVC</acronym>システムを収納します。
  92. </para>
  93. <itemizedlist>
  94. <listitem>
  95. <para>
  96. <emphasis><filename>configs/</filename></emphasis>:
  97. アプリケーション全体の設定のディレクトリ
  98. </para>
  99. </listitem>
  100. <listitem>
  101. <para>
  102. <emphasis><filename>controllers/</filename></emphasis>,
  103. <emphasis><filename>models/</filename></emphasis>,
  104. <emphasis><filename>views/</filename></emphasis>:
  105. これらのディレクトリは、デフォルトのコントローラ、モデルまたは
  106. ビューのディレクトリとして用いられます。
  107. アプリケーション・ディレクトリの中にこれらの3つのディレクトリを持たせると、
  108. グローバルな <filename>controllers/models/views</filename> を持つ
  109. モジュラー・プロジェクトと同様に、
  110. 単純なプロジェクトを始めるための最良のレイアウトが提供されます。
  111. </para>
  112. </listitem>
  113. <listitem>
  114. <para>
  115. <emphasis><filename>controllers/helpers/</filename></emphasis>:
  116. これらのディレクトリにはアクション・ヘルパーを含みます。
  117. アクション・ヘルパーは、デフォルト・モジュールのための
  118. "<classname>Controller_Helper_</classname>"、
  119. または他のモジュールの "&lt;Module&gt;_Controller_Helper" として
  120. namespace されます。
  121. </para>
  122. </listitem>
  123. <listitem>
  124. <para>
  125. <emphasis><filename>layouts/</filename></emphasis>:
  126. このレイアウト・ディレクトリは、 <acronym>MVC</acronym> ベースのレイアウト用です。
  127. <classname>Zend_Layout</classname> は <acronym>MVC</acronym> ベース、
  128. 及び非 <acronym>MVC</acronym> ベースのレイアウトができるので、
  129. このディレクトリの位置は、レイアウトがコントローラとは1対1の関係ではなく、
  130. <filename>views/</filename> 内のテンプレートから独立していることを反映します。
  131. </para>
  132. </listitem>
  133. <listitem>
  134. <para>
  135. <emphasis><filename>modules/</filename></emphasis>:
  136. モジュールにより、開発者は
  137. 一組の関連したコントローラを論理的に系統化されたグループに分類できます。
  138. モジュール・ディレクトリ配下の構造は、
  139. アプリケーション・ディレクトリ配下の構造に似ています。
  140. </para>
  141. </listitem>
  142. <listitem>
  143. <para>
  144. <emphasis><filename>services/</filename></emphasis>:
  145. このディレクトリは、
  146. アプリケーションによって、
  147. またはモデルのための<ulink
  148. url="http://www.martinfowler.com/eaaCatalog/serviceLayer.html">サービス・レイヤ</ulink>
  149. を実装するために提供される、
  150. アプリケーションに依存したウェブ・サービス・ファイルのためのものです。
  151. </para>
  152. </listitem>
  153. <listitem>
  154. <para>
  155. <emphasis><filename>Bootstrap.php</filename></emphasis>:
  156. このファイルはアプリケーションのためのエントリ・ポイントで、
  157. <classname>Zend_Application_Bootstrap_Bootstrapper</classname> を実装するべきです。
  158. このファイルのための目的は、アプリケーションを起動すること、
  159. 及びそれらを初期化することによって、コンポーネントがアプリケーションを利用できるようにすることです。
  160. </para>
  161. </listitem>
  162. </itemizedlist>
  163. </listitem>
  164. <listitem>
  165. <para>
  166. <emphasis><filename>data/</filename></emphasis>:
  167. このディレクトリは、
  168. 揮発性でおそらく一時的なアプリケーションのデータを格納するための場所を提供します。
  169. このディレクトリのデータの障害は、アプリケーションが失敗する原因になるかもしれません。
  170. また、このディレクトリの情報は、サブバージョン・リポジトリに関与するかもしれませんし、
  171. 関与しないかもしれません。
  172. このディレクトリの物体の例は、
  173. セッション・ファイル、キャッシュ・ファイル、sqlite データベース、
  174. そしてログとインデックスです。
  175. </para>
  176. </listitem>
  177. <listitem>
  178. <para>
  179. <emphasis><filename>docs/</filename></emphasis>:
  180. このディレクトリは、生成されたか、または直接編集された
  181. ドキュメンテーションを含みます。
  182. </para>
  183. </listitem>
  184. <listitem>
  185. <para>
  186. <emphasis><filename>library/</filename></emphasis>:
  187. <!-- TODO: to be translated -->
  188. This directory is for
  189. common libraries on which the application depends, and should be on the
  190. <acronym>PHP</acronym> <property>include_path</property>. Developers should
  191. place their application's library code under this directory in a unique
  192. namespace, following the guidelines established in the <acronym>PHP</acronym>
  193. manual's <ulink
  194. url="http://www.php.net/manual/en/userlandnaming.php">Userland Naming
  195. Guide</ulink>, as well as those established by Zend itself. This
  196. directory may also include Zend Framework itself; if so, you would house it in
  197. <filename>library/Zend/</filename>.
  198. </para>
  199. </listitem>
  200. <listitem>
  201. <para>
  202. <emphasis><filename>public/</filename></emphasis>:
  203. このディレクトリは、アプリケーションのためにすべての公開ファイルを含みます。
  204. <!-- TODO: to be translated -->
  205. <filename>index.php</filename> sets up and
  206. invokes <classname>Zend_Application</classname>, which in turn invokes the
  207. <filename>application/Bootstrap.php</filename> file, resulting in dispatching
  208. the front controller. The web root of your web server would typically be set to
  209. this directory.
  210. </para>
  211. </listitem>
  212. <listitem>
  213. <para>
  214. <emphasis><filename>scripts/</filename></emphasis>:
  215. このディレクトリは、メンテナンスやビルド・スクリプトを含みます。
  216. <!-- TODO: to be translated -->
  217. Such scripts might include command line,
  218. cron, or phing build scripts that are not executed at runtime but are part of
  219. the correct functioning of the application.
  220. </para>
  221. </listitem>
  222. <listitem>
  223. <para>
  224. <emphasis><filename>temp/</filename></emphasis>:
  225. The <filename>temp/</filename>
  226. folder is set aside for transient application data. This information would not
  227. typically be committed to the applications svn repository. If data under the
  228. <filename>temp/</filename> directory were deleted, the application should be
  229. able to continue running with a possible decrease in performance until data is
  230. once again restored or recached.
  231. </para>
  232. </listitem>
  233. <listitem>
  234. <para>
  235. <emphasis><filename>tests/</filename></emphasis>:
  236. This directory contains
  237. application tests. These could be hand-written, PHPUnit tests, Selenium-RC
  238. based tests or based on some other testing framework. By default, library code
  239. can be tested by mimicing the directory structure of your
  240. <filename>library/</filename> directory. Additionally, functional tests for
  241. your application could be written mimicing the
  242. <filename>application/</filename> directory structure (including the
  243. application subdirectory).
  244. </para>
  245. </listitem>
  246. </itemizedlist>
  247. </sect1>
  248. <sect1 id="project-structure.filesystem">
  249. <title>モジュール構造</title>
  250. <para>
  251. The directory structure for modules should mimic that of the
  252. <filename>application/</filename> directory in the recommended project structure:
  253. </para>
  254. <programlisting language="xml"><![CDATA[
  255. <modulename>
  256. configs/
  257. application.ini
  258. controllers/
  259. helpers/
  260. forms/
  261. layouts/
  262. filters/
  263. helpers/
  264. scripts/
  265. models/
  266. services/
  267. views/
  268. filters/
  269. helpers/
  270. scripts/
  271. Bootstrap.php
  272. ]]></programlisting>
  273. <para>
  274. The purpose of these directories remains exactly the same as for the recommended
  275. project directory structure.
  276. </para>
  277. </sect1>
  278. <sect1 id="project-structure.rewrite">
  279. <title>リライト設定ガイド</title>
  280. <para>
  281. <acronym>URL</acronym> rewriting is a common function of <acronym>HTTP</acronym>
  282. servers. However, the rules and configuration differ widely between them. Below are
  283. some common approaches across a variety of popular web servers available at the time of
  284. writing.
  285. </para>
  286. <sect2 id="project-structure.rewrite.apache">
  287. <title>Apache HTTPサーバ</title>
  288. <para>
  289. All examples that follow use <property>mod_rewrite</property>, an official
  290. module that comes bundled with Apache. To use it,
  291. <property>mod_rewrite</property> must either be included at compile time or
  292. enabled as a Dynamic Shared Object (<acronym>DSO</acronym>). Please consult the
  293. <ulink url="http://httpd.apache.org/docs/">Apache documentation</ulink> for your
  294. version for more information.
  295. </para>
  296. <sect3 id="project-structure.rewrite.apache.vhost">
  297. <title>バーチャルホスト内でのリライト</title>
  298. <para>
  299. Here is a very basic virtual host definition. These rules direct all requests
  300. to <filename>index.php</filename>, except when a matching file is found under
  301. the <property>document_root</property>.
  302. </para>
  303. <programlisting language="xml"><![CDATA[
  304. <VirtualHost my.domain.com:80>
  305. ServerName my.domain.com
  306. DocumentRoot /path/to/server/root/my.domain.com/public
  307. RewriteEngine off
  308. <Location />
  309. RewriteEngine On
  310. RewriteCond %{REQUEST_FILENAME} -s [OR]
  311. RewriteCond %{REQUEST_FILENAME} -l [OR]
  312. RewriteCond %{REQUEST_FILENAME} -d
  313. RewriteRule ^.*$ - [NC,L]
  314. RewriteRule ^.*$ /index.php [NC,L]
  315. </Location>
  316. </VirtualHost>
  317. ]]></programlisting>
  318. <para>
  319. Note the slash ("/") prefixing <filename>index.php</filename>; the rules for
  320. <filename>.htaccess</filename> differ in this regard.
  321. </para>
  322. </sect3>
  323. <sect3 id="project-structure.rewrite.apache.htaccess">
  324. <title>.htaccessファイル内でのリライト</title>
  325. <para>
  326. 下記は<property>mod_rewrite</property>を利用する
  327. <filename>.htaccess</filename>ファイルの例です。
  328. It is similar to the virtual host
  329. configuration, except that it specifies only the rewrite rules, and the leading
  330. slash is omitted from <filename>index.php</filename>.
  331. </para>
  332. <programlisting language="text"><![CDATA[
  333. RewriteEngine On
  334. RewriteCond %{REQUEST_FILENAME} -s [OR]
  335. RewriteCond %{REQUEST_FILENAME} -l [OR]
  336. RewriteCond %{REQUEST_FILENAME} -d
  337. RewriteRule ^.*$ - [NC,L]
  338. RewriteRule ^.*$ index.php [NC,L]
  339. ]]></programlisting>
  340. <para>
  341. <property>mod_rewrite</property>を設定する方法はたくさんあります。
  342. もし、詳細をお好みでしたら、Jayson Minard の<ulink
  343. url="http://devzone.zend.com/a/70">Blueprint for PHP Applications:
  344. Bootstrapping</ulink>をご覧下さい。
  345. </para>
  346. </sect3>
  347. </sect2>
  348. <sect2 id="project-structure.rewrite.iis">
  349. <title>Microsoft Internet Information サーバ</title>
  350. <para>
  351. As of version 7.0, <acronym>IIS</acronym> now ships with a standard rewrite engine.
  352. You may use the following configuration to create the appropriate rewrite rules.
  353. </para>
  354. <programlisting language="xml"><![CDATA[
  355. <?xml version="1.0" encoding="UTF-8"?>
  356. <configuration>
  357. <system.webServer>
  358. <rewrite>
  359. <rules>
  360. <rule name="Imported Rule 1" stopProcessing="true">
  361. <match url="^.*$" />
  362. <conditions logicalGrouping="MatchAny">
  363. <add input="{REQUEST_FILENAME}"
  364. matchType="IsFile" pattern=""
  365. ignoreCase="false" />
  366. <add input="{REQUEST_FILENAME}"
  367. matchType="IsDirectory"
  368. pattern=""
  369. ignoreCase="false" />
  370. </conditions>
  371. <action type="None" />
  372. </rule>
  373. <rule name="Imported Rule 2" stopProcessing="true">
  374. <match url="^.*$" />
  375. <action type="Rewrite" url="index.php" />
  376. </rule>
  377. </rules>
  378. </rewrite>
  379. </system.webServer>
  380. </configuration>
  381. ]]></programlisting>
  382. </sect2>
  383. </sect1>
  384. </appendix>