Zend_Tool-Usage-CLI.xml 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 22745 -->
  3. <!-- Reviewed: no -->
  4. <sect1 id="zend.tool.usage.cli">
  5. <title>Usando Zend_Tool na Linha de Comando</title>
  6. <para>
  7. O <acronym>CLI</acronym>, ou ferramenta de linha de comando (internamente conhecida como ferramenta de console),
  8. é a principal interface para envio de requisições <classname>Zend_Tool</classname>.
  9. Com a ferramenta <acronym>CLI</acronym>, desenvolvedores podem emitir requisições para a ferramenta
  10. dentro da "janela de linha de comando", também comumente conhecida como uma janela do "terminal". Este
  11. ambiente é predominante em um contexto *nix, porem tem uma implementação comum
  12. no windows com o <filename>cmd.exe</filename>, console2 e também com o projeto Cygwin.
  13. </para>
  14. <!--
  15. <sect2 id="zend.tool.usage.cli.introduction">
  16. <title>Introduction</title>
  17. </sect2>
  18. -->
  19. <sect2 id="zend.tool.usage.cli.installation">
  20. <title>Instalação</title>
  21. <sect3 id="zend.tool.usage.cli.installation.download-and-go">
  22. <title>Download E Siga</title>
  23. <para>
  24. Primeiro faça o download do Zend Framework. Isto pode ser feito indo em framework.zend.com
  25. e fazendo download do último release. Depois que você fez o download do pacote e colocou-o
  26. no seu sistem. O próximo passo é deixar o comando zf disponível para seu sistema
  27. O caminho mais fácil de fazer isso, é copiar os próprios arquivos do diretório bin/
  28. do download, e colocar esses arquivos no <emphasis>mesmo</emphasis> diretório local do
  29. binário do cli <acronym>PHP</acronym>.
  30. </para>
  31. </sect3>
  32. <sect3 id="zend.tool.usage.cli.installation.pear">
  33. <title>Instalação Via Pear</title>
  34. <para>
  35. Para instalar via PEAR, você deve usar o site de terceiros zfcampus.org para obter o
  36. último pacote PEAR do Zend Framework. Estes pacotes são tipicamente construídos dentro
  37. de um dia de um release oficial do Zend Framework. O benefício da instalação via gerenciador
  38. de pacotes PEAR é que durante o processo de instalação, a biblioteca ZF vai acabar no
  39. include_path, e os scripts zf.php e zf scripts irão acabar em um lugar no seu sistema
  40. que vai permitir executar-los sem nenhuma configuração adicional.
  41. </para>
  42. <programlisting language="text"><![CDATA[
  43. pear discover-channel pear.zfcampus.org
  44. pear install zfcampus/zf
  45. ]]></programlisting>
  46. <para>
  47. That is it. After the initial install, you should be able to continue on by
  48. running the zf command. Go good way to check to see if it't there is to run
  49. zf --help
  50. </para>
  51. </sect3>
  52. <sect3 id="zend.tool.usage.cli.installation.install-by-hand">
  53. <title>Instalação na Mão</title>
  54. <para>
  55. Instalação na mão refere-se ao processo de forçar o zf.php e a biblioteca Zend Framework
  56. a trabalhar juntas quando elas são colocadas em lugares não-convencionais, ou pelo menos,
  57. em um lugar que seu sistema não pode dispachar facilmente (típico de programas no PATH
  58. do seu sistema).
  59. </para>
  60. <para>
  61. Se você está em um sistema *nix ou mac, você pode também criar um link de algum lugar
  62. no seu path para o arquivo zf.sh. Se fizer isso, você não precisa se preocupar em ter
  63. a biblioteca Zend Framework no seu include_path, como os arquivos zf.php e zf.sh serão
  64. capazes de acessar a biblioteca em relação a onde elas estão (significa que os arquivos
  65. no ./bin/ são ../library/ relativos a biblioteca Zend Framework).
  66. </para>
  67. <para>
  68. Existe um número de outras opções disponíveis para configurar o zf.php e a biblioteca
  69. no seu sistema. Essas opções giram em torno da definição de variáveis específicas de
  70. ambiente. Estas serão descritas mais tarde na seção "customizando o ambiente CLI". As
  71. variáveis de ambiente para configurar o zf.php no include_path, ZF_INCLUDE_PATH e
  72. ZF_INCLUDE_PATH_PREPEND, são as mais interessantes.
  73. </para>
  74. </sect3>
  75. </sect2>
  76. <sect2 id="zend.tool.usage.cli.general-purpose-commands">
  77. <title>General Purpose Commands</title>
  78. <sect3 id="zend.tool.usage.cli.general-purpose-commands.version">
  79. <title>Version</title>
  80. <para>
  81. This will show the current version number of the copy of Zend Framework the zf.php
  82. tool is using.
  83. </para>
  84. <programlisting language="text"><![CDATA[
  85. zf show version
  86. ]]></programlisting>
  87. </sect3>
  88. <sect3 id="zend.tool.usage.cli.general-purpose-commands.built-in-help">
  89. <title>Built-in Help</title>
  90. <para>
  91. The built-in help system is the primary place where you can get up-to-date
  92. information on what your system is capable of doing. The help system is dynamic in
  93. that as providers are added to your system, they are automatically dispatchable, and
  94. as such, the parameters required to run them will be in the help screen. The
  95. easiest way to retrieve the help screen is the following:
  96. </para>
  97. <programlisting language="text"><![CDATA[
  98. zf --help
  99. ]]></programlisting>
  100. <para>
  101. This will give you an overview of the various capabilities of the system.
  102. Sometimes, there are more finite commands than can be run, and to gain more
  103. information about these, you might have to run a more specialized help command.
  104. For specialized help, simply replace any of the elements of the command with a "?".
  105. This will tell the help system that you want more information about what commands
  106. can go in place of the question mark. For example:
  107. </para>
  108. <programlisting language="text"><![CDATA[
  109. zf ? controller
  110. ]]></programlisting>
  111. <para>
  112. The above means "show me all 'actions' for the provider 'controller'"; while the
  113. following:
  114. </para>
  115. <programlisting language="text"><![CDATA[
  116. zf show ?
  117. ]]></programlisting>
  118. <para>
  119. means "show me all providers that support the 'show' action". This works for
  120. drilling down into options as well as you can see in the following examples:
  121. </para>
  122. <programlisting language="text"><![CDATA[
  123. zf show version.? (show any specialties)
  124. zf show version ? (show any options)
  125. ]]></programlisting>
  126. </sect3>
  127. <sect3 id="zend.tool.usage.cli.general-purpose-commands.manifest">
  128. <title>Manifest</title>
  129. <para>
  130. This will show what information is in the tooling systems manifest. This is more
  131. important for provider developers than casual users of the tooling system.
  132. </para>
  133. <programlisting language="text"><![CDATA[
  134. zf show manifest
  135. ]]></programlisting>
  136. </sect3>
  137. <!--
  138. <sect3 id="zend.tool.usage.cli.general-purpose-commands.tool-configuration">
  139. <title>Tool Configuration</title>
  140. <para>Placeholder need docs from @beberli </para>
  141. </sect3>
  142. -->
  143. </sect2>
  144. <sect2 id="zend.tool.usage.cli.project-specific-commands">
  145. <title>Project Specific Commands</title>
  146. <sect3 id="zend.tool.usage.cli.project-specific-commands.project">
  147. <title>Project</title>
  148. <para>
  149. The project provider is the first command you might want to run. This will setup the
  150. basic structure of your application. This is required before any of the other
  151. providers can be executed.
  152. </para>
  153. <programlisting language="text"><![CDATA[
  154. zf create project MyProjectName
  155. ]]></programlisting>
  156. <para>
  157. This will create a project in a directory called ./MyProjectName. From this point
  158. on, it is important to note that any subsequent commands on the command line must be
  159. issued from within the project directory you had just created. So, after creation,
  160. changing into that directory is required.
  161. </para>
  162. </sect3>
  163. <sect3 id="zend.tool.usage.cli.project-specific-commands.module">
  164. <title>Project</title>
  165. <para>
  166. The module provider allows for the easy creation of a Zend Framework module. A
  167. module follows the hMVC pattern loosely. When creating modules, it will take the
  168. same structure used at the application/ level, and duplicate it inside of the chosen
  169. name for your module, inside of the "modules" directory of the application/
  170. directory without duplicating the modules directory itself. For example:
  171. </para>
  172. <programlisting language="text"><![CDATA[
  173. zf create module Blog
  174. ]]></programlisting>
  175. <para>
  176. This will create a module named Blog at application/modules/Blog, and all of the
  177. artifacts that a module will need.
  178. </para>
  179. </sect3>
  180. <sect3 id="zend.tool.usage.cli.project-specific-commands.controller">
  181. <title>Controller</title>
  182. <para>
  183. The controller provider is responsible for creating (mostly) empty controllers as
  184. well as their corresponding view script directories and files. To utilize it to
  185. create an 'Auth' controlller, for example, execute:
  186. </para>
  187. <programlisting language="text"><![CDATA[
  188. zf create controller Auth
  189. ]]></programlisting>
  190. <para>
  191. This will create a controller named Auth, specifically it will create a file at
  192. application/controllers/AuthController.php with the AuthController inside.
  193. If you wish to create a controller for a module, use any of the following:
  194. </para>
  195. <programlisting language="text"><![CDATA[
  196. zf create controller Post 1 Blog
  197. zf create controller Post -m Blog
  198. zf create controller Post --module=Blog
  199. ]]></programlisting>
  200. <para>
  201. Note: In the first command, 1 is the value for the "includeIndexAction" flag.
  202. </para>
  203. </sect3>
  204. <sect3 id="zend.tool.usage.cli.project-specific-commands.action">
  205. <title>Action</title>
  206. <para>
  207. To create an action within an existing controller:
  208. </para>
  209. <programlisting language="text"><![CDATA[
  210. zf create action login Auth
  211. zf create action login -c Auth
  212. zf create action login --controller-name=Auth
  213. ]]></programlisting>
  214. </sect3>
  215. <sect3 id="zend.tool.usage.cli.project-specific-commands.view">
  216. <title>View</title>
  217. <para>
  218. To create a view outside of the normal controller/action creation, you would use
  219. one of the following:
  220. </para>
  221. <programlisting language="text"><![CDATA[
  222. zf create view Auth my-script-name
  223. zf create view -c Auth -a my-script-name
  224. ]]></programlisting>
  225. <para>
  226. This will create a view script in the controller folder of Auth.
  227. </para>
  228. </sect3>
  229. <sect3 id="zend.tool.usage.cli.project-specific-commands.model">
  230. <title>Model</title>
  231. <para>
  232. The model provider is only responsible for creating the proper model files,
  233. with the proper name inside the application folder. For example
  234. </para>
  235. <programlisting language="text"><![CDATA[
  236. zf create model User
  237. ]]></programlisting>
  238. <para>
  239. If you wish to create a model within a specific module:
  240. </para>
  241. <programlisting language="text"><![CDATA[
  242. zf create model Post -m Blog
  243. ]]></programlisting>
  244. <para>
  245. The above will create a 'Post' model inside of the 'Blog' module.
  246. </para>
  247. </sect3>
  248. <sect3 id="zend.tool.usage.cli.project-specific-commands.form">
  249. <title>Form</title>
  250. <para>
  251. The form provider is only responsible for creating the proper form file and
  252. init() method, with the proper name inside the application folder. For example:
  253. </para>
  254. <programlisting language="text"><![CDATA[
  255. zf create form Auth
  256. ]]></programlisting>
  257. <para>
  258. If you wish to create a model within a specific module:
  259. </para>
  260. <programlisting language="text"><![CDATA[
  261. zf create form Comment -m Blog
  262. ]]></programlisting>
  263. <para>
  264. The above will create a 'Comment' form inside of the 'Blog' module.
  265. </para>
  266. </sect3>
  267. <sect3 id="zend.tool.usage.cli.project-specific-commands.database-adapter">
  268. <title>DbAdapter</title>
  269. <para>
  270. To configure a DbAdapter, you will need to provide the information as a url
  271. encoded string. This string needs to be in quotes on the command line.
  272. </para>
  273. <para>
  274. For example, to enter the following information:
  275. <itemizedlist>
  276. <listitem>
  277. <para>adapter: Pdo_Mysql</para>
  278. </listitem>
  279. <listitem>
  280. <para>username: test</para>
  281. </listitem>
  282. <listitem>
  283. <para>password: test</para>
  284. </listitem>
  285. <listitem>
  286. <para>dbname: test </para>
  287. </listitem>
  288. </itemizedlist>
  289. The following will have to be run on the command line:
  290. </para>
  291. <programlisting language="text"><![CDATA[
  292. zf configure dbadapter "adapter=Pdo_Mysql&username=test&password=test&dbname=test"
  293. ]]></programlisting>
  294. <para>
  295. This assumes you wish to store this information inside of the
  296. 'production' space of the application configuration file. The following will
  297. demonstrate an sqlite configuration, in the 'development' section of the
  298. application config file.
  299. </para>
  300. <programlisting language="text"><![CDATA[
  301. zf configure dbadapter "adapter=Pdo_Sqlite&dbname=../data/test.db" development
  302. zf configure dbadapter "adapter=Pdo_Sqlite&dbname=../data/test.db" -s development
  303. ]]></programlisting>
  304. </sect3>
  305. <sect3 id="zend.tool.usage.cli.project-specific-commands.db-table">
  306. <title>DbTable</title>
  307. <para>
  308. The DbTable provider is responsible for creating
  309. <classname>Zend_Db_Table</classname> model/data access files for your application to
  310. consume, with the proper class name, and in the proper location in the application.
  311. The two important pieces of information are the <emphasis>DbTable name</emphasis>,
  312. and the <emphasis>actual database table name</emphasis>. For example:
  313. </para>
  314. <programlisting language="text"><![CDATA[
  315. zf create dbtable User user
  316. zf create dbtable User -a user
  317. // also accepts a force option to overwrite existing files
  318. zf create dbtable User user -f
  319. zf create dbtable User user --force-override
  320. ]]></programlisting>
  321. <para>
  322. The DbTable provider is also capable of creating the proper files by
  323. scanning the database configured with the above DbAdapter provider.
  324. </para>
  325. <programlisting language="text"><![CDATA[
  326. zf create dbtable.from-database
  327. ]]></programlisting>
  328. <para>
  329. When executing the above, it might make sense to use the pretend / "-p"
  330. flag first so that you can see what would be done, and what tables can
  331. be found in the database.
  332. </para>
  333. <programlisting language="text"><![CDATA[
  334. zf -p create dbtable.from-database
  335. ]]></programlisting>
  336. </sect3>
  337. <sect3 id="zend.tool.usage.cli.project-specific-commands.layout">
  338. <title>Layout</title>
  339. <para>
  340. Currently, the only supported action for layouts is simply to enable them
  341. will setup the proper keys in the application.ini file for the application
  342. resource to work, and create the proper directories and layout.phtml file.
  343. </para>
  344. <programlisting language="text"><![CDATA[
  345. zf enable layout
  346. ]]></programlisting>
  347. </sect3>
  348. </sect2>
  349. <sect2 id="zend.tool.usage.cli.environment-customization">
  350. <title>Environment Customization</title>
  351. <sect3 id="zend.tool.usage.cli.environment-customization.storage-directory">
  352. <title>The Storage Directory</title>
  353. <para>
  354. The storage directory is important so that providers may have a place to find
  355. custom user generated logic that might change the way they behave. One example
  356. can be found below is the placement of a custom project profile file.
  357. </para>
  358. <programlisting language="text"><![CDATA[
  359. zf --setup storage-directory
  360. ]]></programlisting>
  361. </sect3>
  362. <sect3 id="zend.tool.usage.cli.environment-customization.configuration-file">
  363. <title>The Configuration File</title>
  364. <para>
  365. This will create the proper zf.ini file. This <emphasis>should</emphasis>
  366. be run after <command>zf --setup storage-directory</command>. If it is not, it will
  367. be located inside the users home directory. If it is, it will be located inside
  368. the users storage directory.
  369. </para>
  370. <programlisting language="text"><![CDATA[
  371. zf --setup config-file
  372. ]]></programlisting>
  373. </sect3>
  374. <sect3 id="zend.tool.usage.cli.environment-customization.environment-locations">
  375. <title>Environment Locations</title>
  376. <para>
  377. These should be set if you wish to override the default places where zf will
  378. attempt to read their values.
  379. </para>
  380. <itemizedlist>
  381. <listitem>
  382. <para>ZF_HOME</para>
  383. <itemizedlist>
  384. <listitem>
  385. <para>the directory this tool will look for a home directory</para>
  386. </listitem>
  387. <listitem><para>directory must exist</para></listitem>
  388. <listitem>
  389. <para>search order:</para>
  390. <itemizedlist>
  391. <listitem><para>ZF_HOME environment variable</para></listitem>
  392. <listitem><para>HOME environment variable</para></listitem>
  393. <listitem><para>then HOMEPATH environment variable</para></listitem>
  394. </itemizedlist>
  395. </listitem>
  396. </itemizedlist>
  397. </listitem>
  398. <listitem>
  399. <para>ZF_STORAGE_DIRECTORY</para>
  400. <itemizedlist>
  401. <listitem>
  402. <para>where this tool will look for a storage directory</para>
  403. </listitem>
  404. <listitem><para>directory must exist</para></listitem>
  405. <listitem>
  406. <para>search order:</para>
  407. <itemizedlist>
  408. <listitem>
  409. <para>ZF_STORAGE_DIRECTORY environment variable</para>
  410. </listitem>
  411. <listitem><para>$homeDirectory/.zf/ directory</para></listitem>
  412. </itemizedlist>
  413. </listitem>
  414. </itemizedlist>
  415. </listitem>
  416. <listitem>
  417. <para>ZF_CONFIG_FILE</para>
  418. <itemizedlist>
  419. <listitem>
  420. <para>where this tool will look for a configuration file</para>
  421. </listitem>
  422. <listitem>
  423. <para>search order:</para>
  424. <itemizedlist>
  425. <listitem>
  426. <para>ZF_CONFIG_FILE environment variable</para>
  427. </listitem>
  428. <listitem>
  429. <para>$homeDirectory/.zf.ini file if it exists</para>
  430. </listitem>
  431. <listitem>
  432. <para>$storageDirectory/zf.ini file if it exists</para>
  433. </listitem>
  434. </itemizedlist>
  435. </listitem>
  436. </itemizedlist>
  437. </listitem>
  438. <listitem>
  439. <para>ZF_INCLUDE_PATH</para>
  440. <itemizedlist>
  441. <listitem>
  442. <para>set the include_path for this tool to use this value</para>
  443. </listitem>
  444. <listitem>
  445. <para>original behavior:</para>
  446. <itemizedlist>
  447. <listitem>
  448. <para>
  449. use <acronym>PHP</acronym>'s include_path to find ZF
  450. </para>
  451. </listitem>
  452. <listitem>
  453. <para>use the ZF_INCLUDE_PATH environment variable</para>
  454. </listitem>
  455. <listitem>
  456. <para>
  457. use the path ../library (relative to zf.php) to find ZF
  458. </para>
  459. </listitem>
  460. </itemizedlist>
  461. </listitem>
  462. </itemizedlist>
  463. </listitem>
  464. <listitem>
  465. <para>ZF_INCLUDE_PATH_PREPEND</para>
  466. <itemizedlist>
  467. <listitem>
  468. <para>prepend the current php.ini include_path with this value</para>
  469. </listitem>
  470. </itemizedlist>
  471. </listitem>
  472. </itemizedlist>
  473. </sect3>
  474. </sect2>
  475. </sect1>