Zend_Tool_Framework-Architecture.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 15223 -->
  3. <!-- Reviewed: no -->
  4. <sect1 id="zend.tool.framework.architecture">
  5. <title>Architecture</title>
  6. <sect2 id="zend.tool.framework.architecture.registry">
  7. <title>Registry</title>
  8. <para>
  9. Because providers and manifests may come from anywhere in the
  10. <code>include_path</code>, a registry is provided to simplify access
  11. to the various pieces of the toolchain. This registry is injected
  12. into registry-aware components, which may then pull dependencies
  13. from them as necessary. Most dependencies registered with the
  14. registry will be sub-component-specific repositories.
  15. </para>
  16. <para>
  17. The interface for the registry consists of the following definition:
  18. </para>
  19. <programlisting role="php"><![CDATA[
  20. interface Zend_Tool_Framework_Registry_Interface
  21. {
  22. public function setClient(Zend_Tool_Framework_Client_Abstract $client);
  23. public function getClient();
  24. public function setLoader(Zend_Tool_Framework_Loader_Abstract $loader);
  25. public function getLoader();
  26. public function setActionRepository(
  27. Zend_Tool_Framework_Action_Repository $actionRepository
  28. );
  29. public function getActionRepository();
  30. public function setProviderRepository(
  31. Zend_Tool_Framework_Provider_Repository $providerRepository
  32. );
  33. public function getProviderRepository();
  34. public function setManifestRepository(
  35. Zend_Tool_Framework_Manifest_Repository $manifestRepository
  36. );
  37. public function getManifestRepository();
  38. public function setRequest(Zend_Tool_Framework_Client_Request $request);
  39. public function getRequest();
  40. public function setResponse(Zend_Tool_Framework_Client_Response $response);
  41. public function getResponse();
  42. }
  43. ]]></programlisting>
  44. <para>
  45. The various objects the registry manages will be discussed in their
  46. appropriate sections.
  47. </para>
  48. <para>
  49. Classes that should be registry-aware should implement
  50. <classname>Zend_Tool_Framework_Registry_EnabledInterface</classname>. This
  51. interface merely allows initialization of the registry in the target
  52. class.
  53. </para>
  54. <programlisting role="php"><![CDATA[
  55. interface Zend_Tool_Framework_Registry_EnabledInterface
  56. {
  57. public function setRegistry(
  58. Zend_Tool_Framework_Registry_Interface $registry
  59. );
  60. }
  61. ]]></programlisting>
  62. </sect2>
  63. <sect2 id="zend.tool.framework.architecture.providers">
  64. <title>Providers</title>
  65. <para>
  66. <classname>Zend_Tool_Framework_Provider</classname> represents the functional
  67. or "capability" aspect of the framework. Fundamentally,
  68. <classname>Zend_Tool_Framework_Provider</classname> will provide the
  69. interfaces necessary to produce "providers", or bits of tooling
  70. functionality that can be called and used inside the
  71. <classname>Zend_Tool_Framework</classname> toolchain. The simplistic nature of
  72. implementing this provider interface allows the developer a
  73. "one-stop-shop" of adding functionality/capabilities to
  74. <classname>Zend_Tool_Framework</classname>.
  75. </para>
  76. <para>
  77. The provider interface is an empty interface and enforces no methods
  78. (this is the Marker Interface pattern):
  79. </para>
  80. <programlisting role="php"><![CDATA[
  81. interface Zend_Tool_Framework_Provider_Interface
  82. {}
  83. ]]></programlisting>
  84. <para>
  85. Or, if you wish, you can implement the base (or abstract) Provider
  86. which will give you access to the
  87. <classname>Zend_Tool_Framework_Registry</classname>:
  88. </para>
  89. <programlisting role="php"><![CDATA[
  90. abstract class Zend_Tool_Framework_Provider_Abstract
  91. implements Zend_Tool_Framework_Provider_Interface,
  92. Zend_Tool_Registry_EnabledInterface
  93. {
  94. protected $_registry;
  95. public function setRegistry(
  96. Zend_Tool_Framework_Registry_Interface $registry
  97. );
  98. }
  99. ]]></programlisting>
  100. </sect2>
  101. <sect2 id="zend.tool.framework.architecture.loaders">
  102. <title>Loaders</title>
  103. <para>
  104. The purpose of a Loader is to find Providers and Manifest files that
  105. contain classes which implement either
  106. Zend_Tool_Framework_Provider_Interface or
  107. Zend_Tool_Framework_Manifest_Interface. Once these files are found
  108. by a loader, providers are loaded into the Provider Repository and
  109. manifest metadata is loaded into the Manifest Repository.
  110. </para>
  111. <para>
  112. To implement a loader, one must extend the following abstract class:
  113. </para>
  114. <programlisting role="php"><![CDATA[
  115. abstract class Zend_Tool_Framework_Loader_Abstract
  116. {
  117. abstract protected function _getFiles();
  118. public function load()
  119. {
  120. /** ... */
  121. }
  122. }
  123. ]]></programlisting>
  124. <para>
  125. The _getFiles() method should return an array of files (absolute
  126. paths). The built-in loader supplied with ZF is called the
  127. IncludePath loader. By default, the Tooling framework will use an
  128. include path based loader to find files that might include Providers
  129. or Manifest Metadata objects.
  130. Zend_Tool_Framework_Loader_IncludePathLoader, without any other
  131. options, will search for files inside the include path that end in
  132. Mainfest.php, Tool.php or Provider.php. Once found, they will be
  133. tested (by the load() method of the
  134. Zend_Tool_Framework_Loader_Abstract) to determine if they implement
  135. any of the supported interfaces. If they do, an instance of the
  136. found class is instantiated, and it is appended to the proper
  137. repository.
  138. </para>
  139. <programlisting role="php"><![CDATA[
  140. class Zend_Tool_Framework_Loader_IncludePathLoader
  141. extends Zend_Tool_Framework_Loader_Abstract
  142. {
  143. protected $_filterDenyDirectoryPattern = '.*(/|\\\\).svn';
  144. protected $_filterAcceptFilePattern = '.*(?:Manifest|Provider)\.php$';
  145. protected function _getFiles()
  146. {
  147. /** ... */
  148. }
  149. }
  150. ]]></programlisting>
  151. <para>
  152. As you can see, the IncludePath loader will search all include_paths
  153. for the files that match the $_filterAcceptFilePattern and NOT match
  154. the $_filterDenyDirectoryPattern.
  155. </para>
  156. </sect2>
  157. <sect2 id="zend.tool.framework.architecture.manifests">
  158. <title>Manifests</title>
  159. <para>
  160. In short, the Manifest shall contain specific or arbitrary metadata
  161. that is useful to any provider or client, as well as be responsible
  162. for loading any additional providers into the provider repository.
  163. </para>
  164. <para>
  165. To introduce metadata into the manifest repository, all one must do
  166. is implement the empty Zend_Tool_Framework_Manifest_Interface, and
  167. provide a getMetadata() method which shall return an array of
  168. objects that implement Zend_Tool_Framework_Manifest_Metadata.
  169. </para>
  170. <programlisting role="php"><![CDATA[
  171. interface Zend_Tool_Framework_Manifest_Interface
  172. {
  173. public function getMetadata();
  174. }
  175. ]]></programlisting>
  176. <para>
  177. Metadata objects are loaded (by a loader defined below) into the
  178. Manfiest Repository (Zend_Tool_Framework_Manifest_Repository).
  179. Manifests will be processed after all Providers have been found a
  180. loaded into the provider repository. This shall allow Manifests to
  181. created Metadata objects based on what is currently inside the
  182. provider repository.
  183. </para>
  184. <para>
  185. There are a few different metadata classes that can be used to
  186. describe metadata. The Zend_Tool_Framework_Manifest_Metadata is the
  187. base metadata object. As you can see by the following code snippet,
  188. the base metadata class is fairly lightweight and abstract in
  189. nature:
  190. </para>
  191. <programlisting role="php"><![CDATA[
  192. class Zend_Tool_Framework_Manifest_Basic
  193. {
  194. protected $_type = 'Global';
  195. protected $_name = null;
  196. protected $_value = null;
  197. protected $_reference = null;
  198. public function getType();
  199. public function getName();
  200. public function getValue();
  201. public function getReference();
  202. /** ... */
  203. }
  204. ]]></programlisting>
  205. <para>
  206. There are other built in metadata classes as well for describing
  207. more specialized metadata: ActionMetadata and ProviderMetadata.
  208. These classes will help you describe in more detail metadata that is
  209. specific to either actions or providers, and the reference is
  210. expected to be a reference to an action or a provider respectively.
  211. These classes are described in the follow code snippet.
  212. </para>
  213. <programlisting role="php"><![CDATA[
  214. class Zend_Tool_Framework_Manifest_ActionMetadata
  215. extends Zend_Tool_Framework_Manifest_Metadata
  216. {
  217. protected $_type = 'Action';
  218. protected $_actionName = null;
  219. public function getActionName();
  220. /** ... */
  221. }
  222. class Zend_Tool_Framework_Manifest_ProviderMetadata
  223. extends Zend_Tool_Framework_Manifest_Metadata
  224. {
  225. protected $_type = 'Provider';
  226. protected $_providerName = null;
  227. protected $_actionName = null;
  228. protected $_specialtyName = null;
  229. public function getProviderName();
  230. public function getActionName();
  231. public function getSpecialtyName();
  232. /** ... */
  233. }
  234. ]]></programlisting>
  235. <para>
  236. 'Type' in these classes is used to describe the type of metadata the
  237. object is responsible for. In the cases of the ActionMetadata, the
  238. type would be 'Action', and conversely in the case of the
  239. ProviderMetadata the type is 'Provider'. These metadata types will
  240. also include additional structured information about both the
  241. "thing" they are describing as well as the object (the
  242. ->getReference()) they are referencing with this new metadata.
  243. </para>
  244. <para>
  245. In order to create your own metadata type, all one must do is extend
  246. the base Zend_Tool_Framework_Manifest_Metadata class and return
  247. these new metadata objects via a local Manifest class/object. These
  248. user based classes will live in the Manifest Repository
  249. </para>
  250. <para>
  251. Once these metadata objects are in the repository there are then two
  252. different methods that can be used in order to search for them in
  253. the repository.
  254. </para>
  255. <programlisting role="php"><![CDATA[
  256. class Zend_Tool_Framework_Manifest_Repository
  257. {
  258. /**
  259. * To use this method to search, $searchProperties should contain the names
  260. * and values of the key/value pairs you would like to match within the
  261. * manifest.
  262. *
  263. * For Example:
  264. * $manifestRepository->findMetadatas(array(
  265. * 'action' => 'Foo',
  266. * 'name' => 'cliActionName'
  267. * ));
  268. *
  269. * Will find any metadata objects that have a key with name 'action' value
  270. * of 'Foo', AND a key named 'name' value of 'cliActionName'
  271. *
  272. * Note: to either exclude or include name/value pairs that exist in the
  273. * search critera but do not appear in the object, pass a bool value to
  274. * $includeNonExistentProperties
  275. */
  276. public function findMetadatas(Array $searchProperties = array(),
  277. $includeNonExistentProperties = true);
  278. /**
  279. * The following will return exactly one of the matching search criteria,
  280. * regardless of how many have been returned. First one in the manifest is
  281. * what will be returned.
  282. */
  283. public function findMetadata(Array $searchProperties = array(),
  284. $includeNonExistentProperties = true)
  285. {
  286. $metadatas = $this->getMetadatas($searchProperties,
  287. $includeNonExistentProperties);
  288. return array_shift($metadatas);
  289. }
  290. }
  291. ]]></programlisting>
  292. <para>
  293. Looking at the search methods above, the signatures allow for
  294. extremely flexible searching. In order to find a metadata object,
  295. simply pass in an array of matching constraints via an array. If
  296. the data is accessible through the Property accessor (the
  297. getSomething() methods implemented on the metadata object), then it
  298. will be passed back to the user as a "found" metadata object.
  299. </para>
  300. </sect2>
  301. <sect2 id="zend.tool.framework.architecture.clients">
  302. <title>Clients</title>
  303. <para>
  304. Clients are the interface which bridges a user or external tool into
  305. the Zend_Tool_Framework system. Clients can come in all shapes and
  306. sizes: RPC endpoints, Command Line Interface, or even a web
  307. interface. Zend_Tool has implemented the command line interface as
  308. the default interface for interacting with the Zend_Tool_Framework
  309. system.
  310. </para>
  311. <para>
  312. To implement a client, one would need to extend the following
  313. abstract class:
  314. </para>
  315. <programlisting role="php"><![CDATA[
  316. abstract class Zend_Tool_Framework_Client_Abstract
  317. {
  318. /**
  319. * This method should be implemented by the client implementation to
  320. * construct and set custom loaders, request and response objects.
  321. *
  322. * (not required, but suggested)
  323. */
  324. protected function _preInit();
  325. /**
  326. * This method should be implemented by the client implementation to parse
  327. * out and setup the request objects action, provider and parameter
  328. * information.
  329. */
  330. abstract protected function _preDispatch();
  331. /**
  332. * This method should be implemented by the client implementation to take
  333. * the output of the response object and return it (in an client specific
  334. * way) back to the Tooling Client.
  335. *
  336. * (not required, but suggested)
  337. */
  338. abstract protected function _postDispatch();
  339. }
  340. ]]></programlisting>
  341. <para>
  342. As you can see, there is 1 method required to fulfill the needs of a
  343. client (two othres suggested), the initialization, prehandling and post handling. For a
  344. more in depth study of how the command line client works, please see
  345. <ulink url="http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Tool/Framework/Client/Console.php">source code</ulink>.
  346. </para>
  347. </sect2>
  348. </sect1>