Zend_Tool-Extending.xml 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 20807 -->
  3. <!-- Reviewed: no -->
  4. <sect1 id="zend.tool.extending">
  5. <title>Zend_Tool erweitern</title>
  6. <sect2 id="zend.tool.extending.overview">
  7. <title>Übersicht über Zend_Tool</title>
  8. <para>
  9. <classname>Zend_Tool_Framework</classname> is a framework for exposing common
  10. functionalities such as the creation of project scaffolds, code
  11. generation, search index generation, and much more. Functionality may be
  12. written and exposed via <acronym>PHP</acronym> classes dropped into the
  13. <acronym>PHP</acronym> <property>include_path</property>, providing incredible
  14. flexibility of implementation. The functionality may then be consumed by writing
  15. implementation and/or protocol-specific clients -- such as console
  16. clients, <acronym>XML-RPC</acronym>, <acronym>SOAP</acronym>, and much more.
  17. </para>
  18. <para>
  19. <classname>Zend_Tool_Project</classname> builds on and extends the capabilities of
  20. <classname>Zend_Tool_Framework</classname> to that of managing a "project". In general,
  21. a "project" is a planned endeavor or an initiative. In the computer world, projects
  22. generally are a collection of resources. These resources can be files, directories,
  23. databases, schemas, images, styles, and more.
  24. </para>
  25. </sect2>
  26. <sect2 id="zend.tool.extending.zend-tool-framework">
  27. <title>Zend_Tool_Framework Extensions</title>
  28. <sect3 id="zend.tool.extending.zend-tool-framework.architecture">
  29. <title>Overall Architecture</title>
  30. <para>
  31. <classname>Zend_Tool_Framework</classname> provides the following:
  32. </para>
  33. <itemizedlist>
  34. <listitem>
  35. <para>
  36. <emphasis>Common interfaces and abstracts</emphasis> that allow
  37. developers to create functionality and capabilities that are
  38. dispatchable by tooling clients.
  39. </para>
  40. </listitem>
  41. <listitem>
  42. <para>
  43. <emphasis>Base client functionality</emphasis> and a concrete
  44. console implementation that connect external tools and
  45. interfaces to the <classname>Zend_Tool_Framework</classname>. The Console
  46. client may be used in <acronym>CLI</acronym> environments such as unix
  47. shells and the Windows console.
  48. </para>
  49. </listitem>
  50. <listitem>
  51. <para>
  52. <emphasis>"Provider" and "Manifest" interfaces</emphasis> that
  53. can be utilized by the tooling system. "Providers" represent the
  54. functional aspect of the framework, and define the actions that
  55. tooling clients may call. "Manifests" act as metadata registries
  56. that provide additional context for the various defined
  57. providers.
  58. </para>
  59. </listitem>
  60. <listitem>
  61. <para>
  62. <emphasis>An introspective loading system</emphasis> that will
  63. scan the environment for providers and determine what is
  64. required to dispatch them.
  65. </para>
  66. </listitem>
  67. <listitem>
  68. <para>
  69. <emphasis>A standard set of system providers</emphasis> that
  70. allow the system to report what the full capabilities of the
  71. system are as well as provide useful feedback. This also
  72. includes a comprehensive "Help System".
  73. </para>
  74. </listitem>
  75. </itemizedlist>
  76. <para>
  77. Definitions that you should be aware of through this manual with respect
  78. to <classname>Zend_Tool_Framework</classname> include:
  79. </para>
  80. <itemizedlist>
  81. <listitem><para>
  82. <classname>Zend_Tool_Framework</classname> - The framework which exposes
  83. tooling capabilities.
  84. </para></listitem>
  85. <listitem><para>
  86. <emphasis>Tooling Client</emphasis> - A developer tool that connects
  87. to and consumes <classname>Zend_Tool_Framework</classname>.
  88. </para></listitem>
  89. <listitem><para>
  90. <emphasis>Client</emphasis> - The subsystem of
  91. <classname>Zend_Tool_Framework</classname> that exposes an interface such that
  92. tooling clients can connect, query and execute commands.
  93. </para></listitem>
  94. <listitem><para>
  95. <emphasis>Console Client / Command Line Interface /
  96. <filename>zf.php</filename></emphasis> - The tooling client for the command
  97. line.
  98. </para></listitem>
  99. <listitem><para>
  100. <emphasis>Provider</emphasis> - A subsystem and a collection of
  101. built-in functionality that the framework exports.
  102. </para></listitem>
  103. <listitem><para>
  104. <emphasis>Manifest</emphasis> - A subsystem for defining,
  105. organizing, and disseminating provider requirement data.
  106. </para></listitem>
  107. <listitem><para>
  108. <classname>Zend_Tool_Project</classname> Provider - A set of providers
  109. specifically for creating and maintaining Zend Framework-based
  110. projects.
  111. </para></listitem>
  112. </itemizedlist>
  113. </sect3>
  114. <sect3 id="zend.tool.extending.zend-tool-framework.cli-client">
  115. <title>Understanding the CLI Client</title>
  116. <para>
  117. The <acronym>CLI</acronym>, or command line tool (internally known as the console
  118. tool), is currently the primary interface for dispatching
  119. <classname>Zend_Tool</classname> requests. With the <acronym>CLI</acronym> tool,
  120. developers can issue tooling requests inside the "command line windows", also
  121. commonly known as a "terminal" window. This environment is predominant in the *nix
  122. environment, but also has a common implementation in windows with the
  123. <filename>cmd.exe</filename>, console2 and also with the Cygwin project.
  124. </para>
  125. <sect4 id="zend.tool.extending.zend-tool-framework.cli-client.setup-general">
  126. <title>Setting up the CLI tool</title>
  127. <para>
  128. To issue tooling requests via the command line client, you first
  129. need to set up the client so that your system can handle the "zf"
  130. command. The command line client, for all intents and purposes, is
  131. the <filename>.sh</filename> or <filename>.bat</filename> file that is provided
  132. with your Zend Framework distribution. In trunk, it can be found here:
  133. <ulink
  134. url="http://framework.zend.com/svn/framework/standard/trunk/bin/">http://framework.zend.com/svn/framework/standard/trunk/bin/</ulink>.
  135. </para>
  136. <para>
  137. As you can see, there are 3 files in the <filename>/bin/</filename>
  138. directory: a <filename>zf.php</filename>, <filename>zf.sh</filename>, and
  139. <filename>zf.bat</filename>. The <filename>zf.sh</filename> and the
  140. <filename>zf.bat</filename> are the operating system specific client
  141. wrappers: <filename>zf.sh</filename> for the *nix environment, and
  142. <filename>zf.bat</filename> for the Win32 environment. These client wrappers are
  143. responsible for finding the proper <filename>php.exe</filename>, finding the
  144. <filename>zf.php</filename>, and passing on the client request. The
  145. <filename>zf.php</filename> is the responsible for handling understanding
  146. your environment, constructing the proper include_path, and passing
  147. what is provided on the command line to the proper library component
  148. for dispatching.
  149. </para>
  150. <para>
  151. Ultimately, you want to ensure two things to make everything work
  152. regardless of the operating system you are on:
  153. </para>
  154. <orderedlist>
  155. <listitem>
  156. <para>
  157. <filename>zf.sh/zf.bat</filename> is reachable from your system
  158. path. This is the ability to call <command>zf</command> from
  159. anywhere on your command line, regardless of what your
  160. current working directory is.
  161. </para>
  162. </listitem>
  163. <listitem>
  164. <para>
  165. <filename>ZendFramework/library</filename> is in your
  166. <property>include_path</property>.
  167. </para>
  168. </listitem>
  169. </orderedlist>
  170. <note>
  171. <para>
  172. Note: while the above are the most ideal
  173. requirements, you can simply download Zend Framework and expect it
  174. to work as <filename>./path/to/zf.php</filename> some command.
  175. </para>
  176. </note>
  177. </sect4>
  178. <sect4 id="zend.tool.extending.zend-tool-framework.cli-client.setup-starnix">
  179. <title>Setting up the CLI tool on Unix-like Systems</title>
  180. <para>
  181. The most common setup in the *nix environment, is to copy the
  182. <filename>zf.sh</filename> and <filename>zf.php</filename> into the same
  183. directory as your <acronym>PHP</acronym> binary. This can generally be found in
  184. one of the following places:
  185. </para>
  186. <programlisting language="text"><![CDATA[
  187. /usr/bin
  188. /usr/local/bin
  189. /usr/local/ZendServer/bin/
  190. /Applications/ZendServer/bin/
  191. ]]></programlisting>
  192. <para>
  193. To find out the location of your <acronym>PHP</acronym> binary, you can execute
  194. 'which php' on the command line. This will return the location of the
  195. <acronym>PHP</acronym> binary you will be using to run <acronym>PHP</acronym>
  196. scripts in this environment.
  197. </para>
  198. <para>
  199. The next order of business is to ensure that Zend Framework
  200. library is set up correctly inside of the system <acronym>PHP</acronym>
  201. <property>include_path</property>. To find out where your
  202. <property>include_path</property> is located, you can execute
  203. <command>php -i</command> and look for the <property>include_path</property>
  204. variable, or more succinctly, execute
  205. <command>php -i | grep include_path</command>. Once you have found where
  206. your <property>include_path</property> is located (this will generally be
  207. something like <filename>/usr/lib/php</filename>,
  208. <filename>/usr/share/php</filename>, <filename>/usr/local/lib/php</filename>, or
  209. similar), ensure that the contents of the <filename>/library/</filename>
  210. directory are put inside your <property>include_path</property> specified
  211. directory.
  212. </para>
  213. <para>
  214. Once you have done those two things, you should be able to issue a
  215. command and get back the proper response like this:
  216. </para>
  217. <para>
  218. <inlinegraphic scale="100" align="center" valign="middle"
  219. fileref="figures/zend.tool.framework.cliversionunix.png" format="PNG" />
  220. </para>
  221. <para>
  222. If you do not see this type of output, go back and check your setup
  223. to ensure you have all of the necessary pieces in the proper place.
  224. </para>
  225. <para>
  226. There are a couple of alternative setups you might want to employ
  227. depending on your servers configuration, your level of access, or
  228. for other reasons.
  229. </para>
  230. <para>
  231. <emphasis>Alternative Setup</emphasis> involves keeping the Zend Framework
  232. download together as is, and creating a link from a <constant>PATH</constant>
  233. location to the <filename>zf.sh</filename>. What this means is you can
  234. place the contents of the ZendFramework download into a location
  235. such as <filename>/usr/local/share/ZendFramework</filename>, or more locally
  236. like <filename>/home/username/lib/ZendFramework</filename>, and creating a
  237. symbolic link to the <filename>zf.sh</filename>.
  238. </para>
  239. <para>
  240. Assuming you want to put the link inside <filename>/usr/local/bin</filename>
  241. (this could also work for placing the link inside
  242. <filename>/home/username/bin/</filename> for example) you would issue a
  243. command similar to this: </para>
  244. <programlisting language="sh"><![CDATA[
  245. ln -s /usr/local/share/ZendFramework/bin/zf.sh /usr/local/bin/zf
  246. # OR (for example)
  247. ln -s /home/username/lib/ZendFramework/bin/zf.sh /home/username/bin/zf
  248. ]]></programlisting>
  249. <para>
  250. This will create a link which you should be able to access globally
  251. on the command line.
  252. </para>
  253. </sect4>
  254. <sect4 id="zend.tool.extending.zend-tool-framework.cli-client.setup-windows">
  255. <title>Setting up the CLI tool on Windows</title>
  256. <para>
  257. The most common setup in the Windows Win32 environment, is to copy
  258. the <filename>zf.bat</filename> and <filename>zf.php</filename> into the same
  259. directory as your <acronym>PHP</acronym> binary. This can generally be found in
  260. one of the following places:
  261. </para>
  262. <programlisting language="text"><![CDATA[
  263. C:\PHP
  264. C:\Program Files\ZendServer\bin\
  265. C:\WAMP\PHP\bin
  266. ]]></programlisting>
  267. <para>
  268. You should be able to run <filename>php.exe</filename> on the command line.
  269. If you are not able to, first check the documentation that came with
  270. your <acronym>PHP</acronym> distribution, or ensure that the path to
  271. <filename>php.exe</filename> is in your
  272. Windows <constant>PATH</constant> environment variable.
  273. </para>
  274. <para>
  275. The next order of business is to ensure that Zend Framework
  276. library is set up correctly inside of the system <acronym>PHP</acronym>
  277. <property>include_path</property>. To find out where your
  278. <property>include_path</property> is located, you can type <command>php -i</command> and
  279. look for the <property>include_path</property> variable, or more succinctly
  280. execute <command>php -i | grep include_path</command> if you have Cygwin setup with
  281. grep available. Once you have found where your
  282. <property>include_path</property> is located (this will generally be
  283. something like <filename>C:\PHP\pear</filename>, <filename>C:\PHP\share</filename>,
  284. <filename>C:\Program%20Files\ZendServer\share</filename> or similar), ensure
  285. that the contents of the library/ directory are put inside your
  286. <property>include_path</property> specified directory.
  287. </para>
  288. <para>
  289. Once you have done those two things, you should be able to issue a
  290. command and get back the proper response like this:
  291. </para>
  292. <para>
  293. <inlinegraphic scale="100" align="center" valign="middle"
  294. fileref="figures/zend.tool.framework.cliversionwin32.png" format="PNG" />
  295. </para>
  296. <para>
  297. If you do not see this type of output, go back and check your setup
  298. to ensure you have all of the necessary pieces in the proper place.
  299. </para>
  300. <para>
  301. There are a couple of alternative setups you might want to employ
  302. depending on your server's configuration, your level of access, or
  303. for other reasons.
  304. </para>
  305. <para>
  306. <emphasis>Alternative Setup</emphasis> involves keeping the Zend
  307. Framework download together as is, and altering both your system
  308. <constant>PATH</constant> as well as the <filename>php.ini</filename> file.
  309. In your user's environment, make sure to add
  310. <filename>C:\Path\To\ZendFramework\bin</filename>, so that your
  311. <filename>zf.bat</filename> file is executable. Also, alter the
  312. <filename>php.ini</filename> file to ensure that
  313. <filename>C:\Path\To\ZendFramework\library</filename> is in your
  314. <property>include_path</property>.
  315. </para>
  316. </sect4>
  317. <sect4 id="zend.tool.extending.zend-tool-framework.cli-client.setup-othernotes">
  318. <title>Other Setup Considerations</title>
  319. <para>
  320. If for some reason you do not want Zend Framework library inside
  321. your <property>include_path</property>, there is another option. There are
  322. two special environment variables that <filename>zf.php</filename> will
  323. utilize to determine the location of your Zend Framework
  324. installation.
  325. </para>
  326. <para>
  327. The first is <constant>ZEND_TOOL_INCLUDE_PATH_PREPEND</constant>, which will
  328. prepend the value of this environment variable to the system
  329. (<filename>php.ini</filename>) <property>include_path</property> before loading the
  330. client.
  331. </para>
  332. <para>
  333. Alternatively, you might want to use
  334. <constant>ZEND_TOOL_INCLUDE_PATH</constant> to completely
  335. <emphasis>replace</emphasis> the system <property>include_path</property>
  336. for one that makes sense specifically for the <command>zf</command>
  337. command line tool.
  338. </para>
  339. </sect4>
  340. </sect3>
  341. <sect3 id="zend.tool.extending.zend-tool-framework.providers-and-manifests">
  342. <title>Creating Providers</title>
  343. <para>
  344. In general, a provider, on its own, is nothing more than the shell for a
  345. developer to bundle up some capabilities they wish to dispatch with the
  346. command line (or other) clients. It is an analogue to what a
  347. "controller" is inside of your <acronym>MVC</acronym> application.
  348. </para>
  349. <sect4 id="zend.tool.extending.zend-tool-framework.providers-and-manifests.loading">
  350. <title>How Zend Tool finds your Providers</title>
  351. <para>
  352. By default Zend Tool uses the BasicLoader to find all
  353. the providers that you can run. It recursivly iterates all
  354. include path directories and opens all files that end
  355. with "Manifest.php" or "Provider.php". All classes in these
  356. files are inspected if they implement either
  357. <classname>Zend_Tool_Framework_Provider_Interface</classname>
  358. or <classname>Zend_Tool_Framework_Manifest_ProviderManifestable</classname>.
  359. Instances of the provider interface make up for the real functionality
  360. and all their public methods are accessible as provider actions.
  361. The ProviderManifestable interface however requires the implementation of a method
  362. <methodname>getProviders()</methodname> which returns an array of
  363. instantiated provider interface instances.
  364. </para>
  365. <para>
  366. The following naming rules apply on how you can access the providers
  367. that were found by the IncludePathLoader:
  368. </para>
  369. <itemizedlist>
  370. <listitem>
  371. <para>
  372. The last part of your classname split by underscore is used
  373. for the provider name, e.g. "My_Provider_Hello" leads to your
  374. provider being accessible by the name "hello".
  375. </para>
  376. </listitem>
  377. <listitem>
  378. <para>
  379. If your provider has a method <methodname>getName()</methodname>
  380. it will be used instead of the previous method to determine
  381. the name.
  382. </para>
  383. </listitem>
  384. <listitem>
  385. <para>
  386. If your provider has "Provider" as prefix, e.g. it is called
  387. <classname>My_HelloProvider</classname> it will be stripped
  388. from the name so that the provider will be called "hello".
  389. </para>
  390. </listitem>
  391. </itemizedlist>
  392. <note>
  393. <para>The IncludePathLoader does not follow symlinks, that means
  394. you cannot link provider functionality into your include paths,
  395. they have to be physically present in the include paths.</para>
  396. </note>
  397. <example id="zend.tool.extending.zend-tool-framework.providers-and-manifests.loading.example">
  398. <title>Exposing Your Providers with a Manifest</title>
  399. <para>
  400. You can expose your providers to Zend Tool by offering a manifest
  401. with a special filename ending with "Manifest.php".
  402. A Provider Manifest is an implementation of the
  403. <interface>Zend_Tool_Framework_Manifest_ProviderManifestable</interface>
  404. and requires the <methodname>getProviders()</methodname> method to return
  405. an array of instantiated providers. In anticipation of our first
  406. own provider <classname>My_Component_HelloProvider</classname>
  407. we will create the following manifest:
  408. </para>
  409. <programlisting language="php"><![CDATA[
  410. class My_Component_Manifest
  411. implements Zend_Tool_Framework_Manifest_ProviderManifestable
  412. {
  413. public function getProviders()
  414. {
  415. return array(
  416. new My_Component_HelloProvider()
  417. );
  418. }
  419. }
  420. ]]></programlisting>
  421. </example>
  422. </sect4>
  423. <sect4 id="zend.tool.extending.zend-tool-framework.providers-and-manifests.basic">
  424. <title>Basic Instructions for Creating Providers</title>
  425. <para>
  426. As an example, if a developer wants to add the capability of showing
  427. the version of a datafile that his 3rd party component is working
  428. from, there is only one class the developer would need to implement.
  429. Assuming the component is called <classname>My_Component</classname>, he would
  430. create a class named <classname>My_Component_HelloProvider</classname> in a
  431. file named <filename>HelloProvider.php</filename> somewhere on the
  432. <property>include_path</property>. This class would implement
  433. <classname>Zend_Tool_Framework_Provider_Interface</classname>, and the body of
  434. this file would only have to look like the following:
  435. </para>
  436. <programlisting language="php"><![CDATA[
  437. class My_Component_HelloProvider
  438. implements Zend_Tool_Framework_Provider_Interface
  439. {
  440. public function say()
  441. {
  442. echo 'Hello from my provider!';
  443. }
  444. }
  445. ]]></programlisting>
  446. <para>
  447. Given that code above, and assuming the developer wishes to access
  448. this functionality through the console client, the call would look
  449. like this:
  450. </para>
  451. <programlisting language="sh"><![CDATA[
  452. % zf say hello
  453. Hello from my provider!
  454. ]]></programlisting>
  455. </sect4>
  456. <sect4 id="zend.tool.extending.zend-tool-framework.providers-and-manifests.response">
  457. <title>The response object</title>
  458. <para>
  459. As discussed in the architecture section Zend Tool allows to hook different clients for
  460. using your Zend Tool providers. To keep compliant with different clients you should
  461. use the response object to return messages from your providers instead of using
  462. <methodname>echo()</methodname> or a similiar output mechanism. Rewritting our hello
  463. provider with this knowledge it looks like:
  464. </para>
  465. <programlisting language="php"><![CDATA[
  466. class My_Component_HelloProvider
  467. extends Zend_Tool_Framework_Provider_Abstract
  468. {
  469. public function say()
  470. {
  471. $this->_registry->getResponse
  472. ->appendContent("Hello from my provider!");
  473. }
  474. }
  475. ]]></programlisting>
  476. <para>
  477. As you can see one has to extend the <classname>Zend_Tool_Framework_Provider_Abstract</classname>
  478. to gain access to the Registry which holds the <classname>Zend_Tool_Framework_Client_Response</classname>
  479. instance.
  480. </para>
  481. </sect4>
  482. <sect4 id="zend.tool.extending.zend-tool-framework.providers-and-manifests.advanced">
  483. <title>Advanced Development Information</title>
  484. <sect5 id="zend.tool.extending.zend-tool-framework.providers-and-manifests.advanced.variables">
  485. <title>Passing Variables to a Provider</title>
  486. <para>
  487. The above "Hello World" example is great for simple commands, but
  488. what about something more advanced? As your scripting and tooling
  489. needs grow, you might find that you need the ability to accept
  490. variables. Much like function signatures have parameters, your
  491. tooling requests can also accept parameters.
  492. </para>
  493. <para>
  494. Just as each tooling request can be isolated to a method within a
  495. class, the parameters of a tooling request can also be isolated in a
  496. very well known place. Parameters of the action methods of a
  497. provider can include the same parameters you want your client to
  498. utilize when calling that provider and action combination. For
  499. example, if you wanted to accept a name in the above example, you
  500. would probably do this in OO code:
  501. </para>
  502. <programlisting language="php"><![CDATA[
  503. class My_Component_HelloProvider
  504. implements Zend_Tool_Framework_Provider_Interface
  505. {
  506. public function say($name = 'Ralph')
  507. {
  508. echo 'Hello' . $name . ', from my provider!';
  509. }
  510. }
  511. ]]></programlisting>
  512. <para>
  513. The above example can then be called via the command line
  514. <command>zf say hello Joe</command>. "Joe" will be supplied to the provider as
  515. a parameter of the method call. Also note, as you see that the
  516. parameter is optional, that means it is also optional on the command
  517. line, so that <command>zf say hello</command> will still work, and default
  518. to the name "Ralph".
  519. </para>
  520. </sect5>
  521. <sect5 id="zend.tool.extending.zend-tool-framework.providers-and-manifests.advanced.prompt">
  522. <title>Prompt the User for Input</title>
  523. <para>
  524. There are cases when the workflow of your provider requires
  525. to prompt the user for input. This can be done by requesting
  526. the client to ask for more the required input by calling:
  527. </para>
  528. <programlisting language="php"><![CDATA[
  529. class My_Component_HelloProvider
  530. extends Zend_Tool_Framework_Provider_Abstract
  531. {
  532. public function say($name = 'Ralph')
  533. {
  534. $nameResponse = $this->_registry
  535. ->getClient()
  536. ->promptInteractiveInput("Whats your name?");
  537. $name = $name->getContent();
  538. echo 'Hello' . $name . ', from my provider!';
  539. }
  540. }
  541. ]]></programlisting>
  542. <para>
  543. This command throws an exception if the current client is not
  544. able to handle interactive requests. In case of the default Console Client
  545. however you will be asked to enter the name.
  546. </para>
  547. </sect5>
  548. <sect5 id="zend.tool.extending.zend-tool-framework.providers-and-manifests.advanced.pretendable">
  549. <title>Pretending to execute a Provider Action</title>
  550. <para>
  551. Another interesting feature you might wish to implement is
  552. <emphasis>pretendability</emphasis>. Pretendabilty is the ability
  553. for your provider to "pretend" as if it is doing the requested
  554. action and provider combination and give the user as much
  555. information about what it <emphasis>would</emphasis> do without
  556. actually doing it. This might be an important notion when doing
  557. heavy database or filesystem modifications that the user might not
  558. otherwise want to do.
  559. </para>
  560. <para>
  561. Pretendability is easy to implement. There are two parts to this
  562. feature: 1) marking the provider as having the ability to "pretend",
  563. and 2) checking the request to ensure the current request was indeed
  564. asked to be "pretended". This feature is demonstrated in the code
  565. sample below.
  566. </para>
  567. <programlisting language="php"><![CDATA[
  568. class My_Component_HelloProvider
  569. extends Zend_Tool_Framework_Provider_Abstract
  570. implements Zend_Tool_Framework_Provider_Pretendable
  571. {
  572. public function say($name = 'Ralph')
  573. {
  574. if ($this->_registry->getRequest()->isPretend()) {
  575. echo 'I would say hello to ' . $name . '.';
  576. } else {
  577. echo 'Hello' . $name . ', from my provider!';
  578. }
  579. }
  580. }
  581. ]]></programlisting>
  582. <para>
  583. To run the provider in pretend mode just call:
  584. </para>
  585. <programlisting language="sh"><![CDATA[
  586. % zf --pretend say hello Ralph
  587. I would say hello Ralph.
  588. ]]></programlisting>
  589. </sect5>
  590. <sect5 id="zend.tool.extending.zend-tool-framework.providers-and-manifests.advanced.verbosedebug">
  591. <title>Verbose and Debug modes</title>
  592. <para>
  593. You can also run your provider actions in "verbose" or "debug" modes.
  594. The semantics in regard to this actions have to be implemented by you
  595. in the context of your provider. You can access debug or verbose modes
  596. with:
  597. </para>
  598. <programlisting language="php"><![CDATA[
  599. class My_Component_HelloProvider
  600. implements Zend_Tool_Framework_Provider_Interface
  601. {
  602. public function say($name = 'Ralph')
  603. {
  604. if($this->_registry->getRequest()->isVerbose()) {
  605. echo "Hello::say has been called\n";
  606. }
  607. if($this->_registry->getRequest()->isDebug()) {
  608. syslog(LOG_INFO, "Hello::say has been called\n");
  609. }
  610. }
  611. }
  612. ]]></programlisting>
  613. </sect5>
  614. <sect5 id="zend.tool.extending.zend-tool-framework.providers-and-manifests.advanced.configstorage">
  615. <title>Accessing User Config and Storage</title>
  616. <para>
  617. Using the Enviroment variable <property>ZF_CONFIG_FILE</property> or the
  618. .zf.ini in your home directory you can inject configuration parameters into
  619. any Zend Tool provider. Access to this configuration is available via the
  620. registry that is passed to your provider if you extend
  621. <classname>Zend_Tool_Framework_Provider_Abstract</classname>.
  622. </para>
  623. <programlisting language="php"><![CDATA[
  624. class My_Component_HelloProvider
  625. extends Zend_Tool_Framework_Provider_Abstract
  626. {
  627. public function say()
  628. {
  629. $username = $this->_registry->getConfig()->username;
  630. if(!empty($username)) {
  631. echo "Hello $username!";
  632. } else {
  633. echo "Hello!";
  634. }
  635. }
  636. }
  637. ]]></programlisting>
  638. <para>
  639. The returned configuration is of the type
  640. <classname>Zend_Tool_Framework_Client_Config</classname> but internally the
  641. <methodname>__get()</methodname> and <methodname>__set()</methodname> magic methods
  642. proxy to a <classname>Zend_Config</classname> of the given configuration type.
  643. </para>
  644. <para>
  645. The storage allows to save arbitrary data for later reference. This can be useful for batch
  646. processing tasks or for re-runs of your tasks. You can access the storage in a similar way
  647. like the configuration:
  648. </para>
  649. <programlisting language="php"><![CDATA[
  650. class My_Component_HelloProvider
  651. extends Zend_Tool_Framework_Provider_Abstract
  652. {
  653. public function say()
  654. {
  655. $aValue = $this->_registry->getStorage()->get("myUsername");
  656. echo "Hello $aValue!";
  657. }
  658. }
  659. ]]></programlisting>
  660. <para>
  661. The API of the storage is very simple:
  662. </para>
  663. <programlisting language="php"><![CDATA[
  664. class Zend_Tool_Framework_Client_Storage
  665. {
  666. public function setAdapter($adapter);
  667. public function isEnabled();
  668. public function put($name, $value);
  669. public function get($name, $defaultValue=null);
  670. public function has($name);
  671. public function remove($name);
  672. public function getStreamUri($name);
  673. }
  674. ]]></programlisting>
  675. <important>
  676. <para>
  677. When designing your providers that are config or storage aware remember to
  678. check if the required user-config or storage keys really exist for a user.
  679. You won't run into fatal errors when none of these are provided though,
  680. since empty ones are created upon request.
  681. </para>
  682. </important>
  683. </sect5>
  684. </sect4>
  685. </sect3>
  686. </sect2>
  687. <sect2 id="zend.tool.extending.zend-tool-project">
  688. <title>Zend_Tool_Project Extensions</title>
  689. <para>
  690. Zend_Tool_Project exposes a rich set of functionality and capabilities that make the task
  691. of creating new providers, specficially those targetting project easier and more manageable.
  692. </para>
  693. <sect3 id="zend.tool.extending.zend-tool-project.architecture">
  694. <title>Overall Architecture</title>
  695. <para>
  696. This same concept applies to Zend Framework projects. In Zend Framework projects, you have
  697. controllers, actions, views, models, databases and so on and so forth. In terms of
  698. <classname>Zend_Tool</classname>, we need a way to track these types of resources - thus
  699. <classname>Zend_Tool_Project</classname>.
  700. </para>
  701. <para>
  702. <classname>Zend_Tool_Project</classname> is capable of tracking project resources throughout
  703. the development of a project. So, for example, if in one command you created a controller,
  704. and in the next command you wish to create an action within that controller,
  705. <classname>Zend_Tool_Project</classname> is gonna have to <emphasis>know</emphasis> about
  706. the controller file you created so that you can (in the next action), be able to append that
  707. action to it. This is what keeps our projects up to date and <emphasis>stateful</emphasis>.
  708. </para>
  709. <para>
  710. Another important point to understand about projects is that typically, resources are
  711. organized in a hierarchical fashion. With that in mind,
  712. <classname>Zend_Tool_Project</classname> is capable of serializing the current project into
  713. a internal representation that allows it to keep track of not only <emphasis>what</emphasis>
  714. resources are part of a project at any given time, but also <emphasis>where</emphasis> they
  715. are in relation to one another.
  716. </para>
  717. </sect3>
  718. <sect3 id="zend.tool.extending.zend-tool-project.providers">
  719. <title>Creating Providers</title>
  720. <para>
  721. Project specific providers are created in the same fashion as plain framework providers, with
  722. one exception: project providers must extend the <code>Zend_Tool_Project_Provider_Abstract</code>.
  723. This class comes with some significant functionality that helps developers load existing project,
  724. obtian the profile object, and be able to search the profile, then later store any changes to the
  725. current project profile.
  726. </para>
  727. <programlisting language="php"><![CDATA[
  728. class My_Component_HelloProvider
  729. extends Zend_Tool_Project_Provider_Abstract
  730. {
  731. public function say()
  732. {
  733. $profile = $this->_loadExistingProfile();
  734. /* ... do project stuff here */
  735. $this->_storeProfile();
  736. }
  737. }
  738. ]]></programlisting>
  739. </sect3>
  740. <!--
  741. <sect3 id="zend.tool.extending.zend-tool-project.resources-and-contexts">
  742. <title>Creating Resources &amp; Contexts</title>
  743. </sect3>
  744. -->
  745. </sect2>
  746. </sect1>