project-structure.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <!-- EN-Revision: 18056 -->
  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. <!-- TODO -->
  106. These directories
  107. serve as the default controller, model or view directories. Having
  108. these three directories inside the application directory provides the
  109. best layout for starting a simple project as well as starting a modular
  110. project that has global <filename>controllers/models/views</filename>.
  111. </para>
  112. </listitem>
  113. <listitem>
  114. <para>
  115. <emphasis><filename>controllers/helpers/</filename></emphasis>: These
  116. directories will contain action helpers. Action helpers will be
  117. namespaced either as "<classname>Controller_Helper_</classname>" for
  118. the default module or "&lt;Module&gt;_Controller_Helper" in other
  119. modules.
  120. </para>
  121. </listitem>
  122. <listitem>
  123. <para>
  124. <emphasis><filename>layouts/</filename></emphasis>: This layout
  125. directory is for <acronym>MCV</acronym>-based layouts. Since
  126. <classname>Zend_Layout</classname> is capable of
  127. <acronym>MVC</acronym>- and non-<acronym>MVC</acronym>-based layouts,
  128. the location of this directory reflects that layouts are not on a
  129. 1-to-1 relationship with controllers and are independent of templates
  130. within <filename>views/</filename>.
  131. </para>
  132. </listitem>
  133. <listitem>
  134. <para>
  135. <emphasis><filename>modules/</filename></emphasis>: Modules allow a
  136. developer to group a set of related controllers into a logically
  137. organized group. The structure under the modules directory would
  138. resemble the structure under the application directory.
  139. </para>
  140. </listitem>
  141. <listitem>
  142. <para>
  143. <emphasis><filename>services/</filename></emphasis>: This directory is
  144. for your application specific web-service files that are provided by
  145. your application, or for implementing a <ulink
  146. url="http://www.martinfowler.com/eaaCatalog/serviceLayer.html">Service
  147. Layer</ulink> for your models.
  148. </para>
  149. </listitem>
  150. <listitem>
  151. <para>
  152. <emphasis><filename>Bootstrap.php</filename></emphasis>: This file is
  153. the entry point for your application, and should implement
  154. <classname>Zend_Application_Bootstrap_Bootstrapper</classname>.
  155. The purpose for this file is to bootstrap the application and make
  156. components available to the application by initializing them.
  157. </para>
  158. </listitem>
  159. </itemizedlist>
  160. </listitem>
  161. <listitem>
  162. <para>
  163. <emphasis><filename>data/</filename></emphasis>: This directory provides a
  164. place to store application data that is volatile and possibly temporary. The
  165. disturbance of data in this directory might cause the application to fail.
  166. Also, the information in this directory may or may not be committed to a
  167. subversion repository. Examples of things in this directory are session files,
  168. cache files, sqlite databases, logs and indexes.
  169. </para>
  170. </listitem>
  171. <listitem>
  172. <para>
  173. <emphasis><filename>docs/</filename></emphasis>: This directory contains
  174. documentation, either generated or directly authored.
  175. </para>
  176. </listitem>
  177. <listitem>
  178. <para>
  179. <emphasis><filename>library/</filename></emphasis>: This directory is for
  180. common libraries on which the application depends, and should be on the
  181. <acronym>PHP</acronym> <property>include_path</property>. Developers should
  182. place their application's library code under this directory in a unique
  183. namespace, following the guidelines established in the <acronym>PHP</acronym>
  184. manual's <ulink
  185. url="http://www.php.net/manual/en/userlandnaming.php">Userland Naming
  186. Guide</ulink>, as well as those established by Zend itself. This
  187. directory may also include Zend Framework itself; if so, you would house it in
  188. <filename>library/Zend/</filename>.
  189. </para>
  190. </listitem>
  191. <listitem>
  192. <para>
  193. <emphasis><filename>public/</filename></emphasis>: This directory contains all
  194. public files for your application. <filename>index.php</filename> sets up and
  195. invokes <classname>Zend_Application</classname>, which in turn invokes the
  196. <filename>application/Bootstrap.php</filename> file, resulting in dispatching
  197. the front controller. The web root of your web server would typically be set to
  198. this directory.
  199. </para>
  200. </listitem>
  201. <listitem>
  202. <para>
  203. <emphasis><filename>scripts/</filename></emphasis>: This directory contains
  204. maintenance and/or build scripts. Such scripts might include command line,
  205. cron, or phing build scripts that are not executed at runtime but are part of
  206. the correct functioning of the application.
  207. </para>
  208. </listitem>
  209. <listitem>
  210. <para>
  211. <emphasis><filename>temp/</filename></emphasis>: The <filename>temp/</filename>
  212. folder is set aside for transient application data. This information would not
  213. typically be committed to the applications svn repository. If data under the
  214. <filename>temp/</filename> directory were deleted, the application should be
  215. able to continue running with a possible decrease in performance until data is
  216. once again restored or recached.
  217. </para>
  218. </listitem>
  219. <listitem>
  220. <para>
  221. <emphasis><filename>tests/</filename></emphasis>: This directory contains
  222. application tests. These could be hand-written, PHPUnit tests, Selenium-RC
  223. based tests or based on some other testing framework. By default, library code
  224. can be tested by mimicing the directory structure of your
  225. <filename>library/</filename> directory. Additionally, functional tests for
  226. your application could be written mimicing the
  227. <filename>application/</filename> directory structure (including the
  228. application subdirectory).
  229. </para>
  230. </listitem>
  231. </itemizedlist>
  232. </sect1>
  233. <sect1 id="project-structure.filesystem">
  234. <title>モジュール構造</title>
  235. <para>
  236. The directory structure for modules should mimic that of the
  237. <filename>application/</filename> directory in the recommended project structure:
  238. </para>
  239. <programlisting language="xml"><![CDATA[
  240. <modulename>
  241. configs/
  242. application.ini
  243. controllers/
  244. helpers/
  245. forms/
  246. layouts/
  247. filters/
  248. helpers/
  249. scripts/
  250. models/
  251. services/
  252. views/
  253. filters/
  254. helpers/
  255. scripts/
  256. Bootstrap.php
  257. ]]></programlisting>
  258. <para>
  259. The purpose of these directories remains exactly the same as for the recommended
  260. project directory structure.
  261. </para>
  262. </sect1>
  263. <sect1 id="project-structure.rewrite">
  264. <title>リライト設定ガイド</title>
  265. <para>
  266. <acronym>URL</acronym> rewriting is a common function of <acronym>HTTP</acronym>
  267. servers. However, the rules and configuration differ widely between them. Below are
  268. some common approaches across a variety of popular web servers available at the time of
  269. writing.
  270. </para>
  271. <sect2 id="project-structure.rewrite.apache">
  272. <title>Apache HTTPサーバ</title>
  273. <para>
  274. All examples that follow use <property>mod_rewrite</property>, an official
  275. module that comes bundled with Apache. To use it,
  276. <property>mod_rewrite</property> must either be included at compile time or
  277. enabled as a Dynamic Shared Object (<acronym>DSO</acronym>). Please consult the
  278. <ulink url="http://httpd.apache.org/docs/">Apache documentation</ulink> for your
  279. version for more information.
  280. </para>
  281. <sect3 id="project-structure.rewrite.apache.vhost">
  282. <title>バーチャルホスト内でのリライト</title>
  283. <para>
  284. Here is a very basic virtual host definition. These rules direct all requests
  285. to <filename>index.php</filename>, except when a matching file is found under
  286. the <property>document_root</property>.
  287. </para>
  288. <programlisting language="xml"><![CDATA[
  289. <VirtualHost my.domain.com:80>
  290. ServerName my.domain.com
  291. DocumentRoot /path/to/server/root/my.domain.com/public
  292. RewriteEngine off
  293. <Location />
  294. RewriteEngine On
  295. RewriteCond %{REQUEST_FILENAME} -s [OR]
  296. RewriteCond %{REQUEST_FILENAME} -l [OR]
  297. RewriteCond %{REQUEST_FILENAME} -d
  298. RewriteRule ^.*$ - [NC,L]
  299. RewriteRule ^.*$ /index.php [NC,L]
  300. </Location>
  301. </VirtualHost>
  302. ]]></programlisting>
  303. <para>
  304. Note the slash ("/") prefixing <filename>index.php</filename>; the rules for
  305. <filename>.htaccess</filename> differ in this regard.
  306. </para>
  307. </sect3>
  308. <sect3 id="project-structure.rewrite.apache.htaccess">
  309. <title>.htaccessファイル内でのリライト</title>
  310. <para>
  311. 下記は<property>mod_rewrite</property>を利用する
  312. <filename>.htaccess</filename>ファイルの例です。
  313. It is similar to the virtual host
  314. configuration, except that it specifies only the rewrite rules, and the leading
  315. slash is omitted from <filename>index.php</filename>.
  316. </para>
  317. <programlisting language="text"><![CDATA[
  318. RewriteEngine On
  319. RewriteCond %{REQUEST_FILENAME} -s [OR]
  320. RewriteCond %{REQUEST_FILENAME} -l [OR]
  321. RewriteCond %{REQUEST_FILENAME} -d
  322. RewriteRule ^.*$ - [NC,L]
  323. RewriteRule ^.*$ index.php [NC,L]
  324. ]]></programlisting>
  325. <para>
  326. <property>mod_rewrite</property>を設定する方法はたくさんあります。
  327. もし、詳細をお好みでしたら、Jayson Minard の<ulink
  328. url="http://devzone.zend.com/a/70">Blueprint for PHP Applications:
  329. Bootstrapping</ulink>をご覧下さい。
  330. </para>
  331. </sect3>
  332. </sect2>
  333. <sect2 id="project-structure.rewrite.iis">
  334. <title>Microsoft Internet Information サーバ</title>
  335. <para>
  336. As of version 7.0, <acronym>IIS</acronym> now ships with a standard rewrite engine.
  337. You may use the following configuration to create the appropriate rewrite rules.
  338. </para>
  339. <programlisting language="xml"><![CDATA[
  340. <?xml version="1.0" encoding="UTF-8"?>
  341. <configuration>
  342. <system.webServer>
  343. <rewrite>
  344. <rules>
  345. <rule name="Imported Rule 1" stopProcessing="true">
  346. <match url="^.*$" />
  347. <conditions logicalGrouping="MatchAny">
  348. <add input="{REQUEST_FILENAME}"
  349. matchType="IsFile" pattern=""
  350. ignoreCase="false" />
  351. <add input="{REQUEST_FILENAME}"
  352. matchType="IsDirectory"
  353. pattern=""
  354. ignoreCase="false" />
  355. </conditions>
  356. <action type="None" />
  357. </rule>
  358. <rule name="Imported Rule 2" stopProcessing="true">
  359. <match url="^.*$" />
  360. <action type="Rewrite" url="index.php" />
  361. </rule>
  362. </rules>
  363. </rewrite>
  364. </system.webServer>
  365. </configuration>
  366. ]]></programlisting>
  367. </sect2>
  368. </sect1>
  369. </appendix>