Zend_Tool_Framework-Architecture.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 15343 -->
  3. <!-- Reviewed: no -->
  4. <sect1 id="zend.tool.framework.architecture">
  5. <title>Architektur</title>
  6. <sect2 id="zend.tool.framework.architecture.registry">
  7. <title>Registry</title>
  8. <para>
  9. Weil Provider und Manifeste von überall im <code>include_path</code> kommen können,
  10. wird eine Registry angeboten um den Zugriff auf die verschiedenen Teile der Toolchain
  11. zu vereinfachen. Diese Registry wird in Komponenten eingefügt die registry-aware sind,
  12. und damit Abhängigkeiten entfernen können, wenn das notwendig ist. Die meisten
  13. Abhängigkeiten die in der Registry registriert werden sind Unter-Komponenten
  14. spezifische Repositories.
  15. </para>
  16. <para>
  17. Das Interface für die Registry besteht aus der folgenden 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. Die verschiedenen Objekte welche die Registry managt werden in deren betreffenden
  46. Kapiteln besprochen.
  47. </para>
  48. <para>
  49. Klassen welche Registry-aware sind sollten
  50. <classname>Zend_Tool_Framework_Registry_EnabledInterface</classname> implementieren.
  51. Dieses Interface erlaubt hauptsächlich die Initialisierung der Registry in der
  52. Zielklasse.
  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>Provider</title>
  65. <para>
  66. <classname>Zend_Tool_Framework_Provider</classname> repräsentiert den funktionalen oder
  67. "möglichen" Aspekt des Frameworks. Grundsätzlich bietet
  68. <classname>Zend_Tool_Framework_Provider</classname> das Interface um "Provider" zu
  69. erstellen, oder Teile für Werkzeug-Funktionalität die aufgerufen werden können und in
  70. der <classname>Zend_Tool_Framework</classname> Toolchain verwendet werden. Die einfache
  71. Natur der Implementation dieses Provider Interfaces erlaubt es dem Entwickler ein
  72. "One-Stop-Shop" für das Hinzufügen von Funktionalitäten/Möglichkeiten zu
  73. <classname>Zend_Tool_Framework</classname>.
  74. </para>
  75. <para>
  76. Das Provider Interface ist ein leeres Interface und erzwingt keine Methoden
  77. (das ist das Marker Interface Pattern):
  78. </para>
  79. <programlisting role="php"><![CDATA[
  80. interface Zend_Tool_Framework_Provider_Interface
  81. {}
  82. ]]></programlisting>
  83. <para>
  84. Oder, wenn man das will, kann man den Basis (oder Abstrakten) Provider implementieren,
  85. welcher einem Zugriff auf <classname>Zend_Tool_Framework_Registry</classname> bietet:
  86. </para>
  87. <programlisting role="php"><![CDATA[
  88. abstract class Zend_Tool_Framework_Provider_Abstract
  89. implements Zend_Tool_Framework_Provider_Interface,
  90. Zend_Tool_Registry_EnabledInterface
  91. {
  92. protected $_registry;
  93. public function setRegistry(
  94. Zend_Tool_Framework_Registry_Interface $registry
  95. );
  96. }
  97. ]]></programlisting>
  98. </sect2>
  99. <sect2 id="zend.tool.framework.architecture.loaders">
  100. <title>Loader</title>
  101. <para>
  102. Der Zweck eines Loaders ist es Provider und Manifest Datei zu finden die Klassen
  103. enthalten welche entweder Zend_Tool_Framework_Provider_Interface oder
  104. Zend_Tool_Framework_Manifest_Interface implementieren. Sobald diese Dateien vom
  105. Loader gefunden wurden, werden die Provider in das Provider Repository geladen und
  106. die Manifest Metadaten in das Manifest Repository.
  107. </para>
  108. <para>
  109. Um einen Loader zu implementieren muß man die folgende abstrakte Klasse erweitern:
  110. </para>
  111. <programlisting role="php"><![CDATA[
  112. abstract class Zend_Tool_Framework_Loader_Abstract
  113. {
  114. abstract protected function _getFiles();
  115. public function load()
  116. {
  117. /** ... */
  118. }
  119. }
  120. ]]></programlisting>
  121. <para>
  122. The _getFiles() method should return an array of files (absolute
  123. paths). The built-in loader supplied with ZF is called the
  124. IncludePath loader. By default, the Tooling framework will use an
  125. include path based loader to find files that might include Providers
  126. or Manifest Metadata objects.
  127. Zend_Tool_Framework_Loader_IncludePathLoader, without any other
  128. options, will search for files inside the include path that end in
  129. Mainfest.php, Tool.php or Provider.php. Once found, they will be
  130. tested (by the load() method of the
  131. Zend_Tool_Framework_Loader_Abstract) to determine if they implement
  132. any of the supported interfaces. If they do, an instance of the
  133. found class is instantiated, and it is appended to the proper
  134. repository.
  135. </para>
  136. <programlisting role="php"><![CDATA[
  137. class Zend_Tool_Framework_Loader_IncludePathLoader
  138. extends Zend_Tool_Framework_Loader_Abstract
  139. {
  140. protected $_filterDenyDirectoryPattern = '.*(/|\\\\).svn';
  141. protected $_filterAcceptFilePattern = '.*(?:Manifest|Provider)\.php$';
  142. protected function _getFiles()
  143. {
  144. /** ... */
  145. }
  146. }
  147. ]]></programlisting>
  148. <para>
  149. As you can see, the IncludePath loader will search all include_paths
  150. for the files that match the $_filterAcceptFilePattern and NOT match
  151. the $_filterDenyDirectoryPattern.
  152. </para>
  153. </sect2>
  154. <sect2 id="zend.tool.framework.architecture.manifests">
  155. <title>Manifests</title>
  156. <para>
  157. In short, the Manifest shall contain specific or arbitrary metadata
  158. that is useful to any provider or client, as well as be responsible
  159. for loading any additional providers into the provider repository.
  160. </para>
  161. <para>
  162. To introduce metadata into the manifest repository, all one must do
  163. is implement the empty Zend_Tool_Framework_Manifest_Interface, and
  164. provide a getMetadata() method which shall return an array of
  165. objects that implement Zend_Tool_Framework_Manifest_Metadata.
  166. </para>
  167. <programlisting role="php"><![CDATA[
  168. interface Zend_Tool_Framework_Manifest_Interface
  169. {
  170. public function getMetadata();
  171. }
  172. ]]></programlisting>
  173. <para>
  174. Metadata objects are loaded (by a loader defined below) into the
  175. Manfiest Repository (Zend_Tool_Framework_Manifest_Repository).
  176. Manifests will be processed after all Providers have been found a
  177. loaded into the provider repository. This shall allow Manifests to
  178. created Metadata objects based on what is currently inside the
  179. provider repository.
  180. </para>
  181. <para>
  182. There are a few different metadata classes that can be used to
  183. describe metadata. The Zend_Tool_Framework_Manifest_Metadata is the
  184. base metadata object. As you can see by the following code snippet,
  185. the base metadata class is fairly lightweight and abstract in
  186. nature:
  187. </para>
  188. <programlisting role="php"><![CDATA[
  189. class Zend_Tool_Framework_Manifest_Basic
  190. {
  191. protected $_type = 'Global';
  192. protected $_name = null;
  193. protected $_value = null;
  194. protected $_reference = null;
  195. public function getType();
  196. public function getName();
  197. public function getValue();
  198. public function getReference();
  199. /** ... */
  200. }
  201. ]]></programlisting>
  202. <para>
  203. There are other built in metadata classes as well for describing
  204. more specialized metadata: ActionMetadata and ProviderMetadata.
  205. These classes will help you describe in more detail metadata that is
  206. specific to either actions or providers, and the reference is
  207. expected to be a reference to an action or a provider respectively.
  208. These classes are described in the follow code snippet.
  209. </para>
  210. <programlisting role="php"><![CDATA[
  211. class Zend_Tool_Framework_Manifest_ActionMetadata
  212. extends Zend_Tool_Framework_Manifest_Metadata
  213. {
  214. protected $_type = 'Action';
  215. protected $_actionName = null;
  216. public function getActionName();
  217. /** ... */
  218. }
  219. class Zend_Tool_Framework_Manifest_ProviderMetadata
  220. extends Zend_Tool_Framework_Manifest_Metadata
  221. {
  222. protected $_type = 'Provider';
  223. protected $_providerName = null;
  224. protected $_actionName = null;
  225. protected $_specialtyName = null;
  226. public function getProviderName();
  227. public function getActionName();
  228. public function getSpecialtyName();
  229. /** ... */
  230. }
  231. ]]></programlisting>
  232. <para>
  233. 'Type' in these classes is used to describe the type of metadata the
  234. object is responsible for. In the cases of the ActionMetadata, the
  235. type would be 'Action', and conversely in the case of the
  236. ProviderMetadata the type is 'Provider'. These metadata types will
  237. also include additional structured information about both the
  238. "thing" they are describing as well as the object (the
  239. ->getReference()) they are referencing with this new metadata.
  240. </para>
  241. <para>
  242. In order to create your own metadata type, all one must do is extend
  243. the base Zend_Tool_Framework_Manifest_Metadata class and return
  244. these new metadata objects via a local Manifest class/object. These
  245. user based classes will live in the Manifest Repository
  246. </para>
  247. <para>
  248. Once these metadata objects are in the repository there are then two
  249. different methods that can be used in order to search for them in
  250. the repository.
  251. </para>
  252. <programlisting role="php"><![CDATA[
  253. class Zend_Tool_Framework_Manifest_Repository
  254. {
  255. /**
  256. * To use this method to search, $searchProperties should contain the names
  257. * and values of the key/value pairs you would like to match within the
  258. * manifest.
  259. *
  260. * For Example:
  261. * $manifestRepository->findMetadatas(array(
  262. * 'action' => 'Foo',
  263. * 'name' => 'cliActionName'
  264. * ));
  265. *
  266. * Will find any metadata objects that have a key with name 'action' value
  267. * of 'Foo', AND a key named 'name' value of 'cliActionName'
  268. *
  269. * Note: to either exclude or include name/value pairs that exist in the
  270. * search critera but do not appear in the object, pass a bool value to
  271. * $includeNonExistentProperties
  272. */
  273. public function findMetadatas(Array $searchProperties = array(),
  274. $includeNonExistentProperties = true);
  275. /**
  276. * The following will return exactly one of the matching search criteria,
  277. * regardless of how many have been returned. First one in the manifest is
  278. * what will be returned.
  279. */
  280. public function findMetadata(Array $searchProperties = array(),
  281. $includeNonExistentProperties = true)
  282. {
  283. $metadatas = $this->getMetadatas($searchProperties,
  284. $includeNonExistentProperties);
  285. return array_shift($metadatas);
  286. }
  287. }
  288. ]]></programlisting>
  289. <para>
  290. Looking at the search methods above, the signatures allow for
  291. extremely flexible searching. In order to find a metadata object,
  292. simply pass in an array of matching constraints via an array. If
  293. the data is accessible through the Property accessor (the
  294. getSomething() methods implemented on the metadata object), then it
  295. will be passed back to the user as a "found" metadata object.
  296. </para>
  297. </sect2>
  298. <sect2 id="zend.tool.framework.architecture.clients">
  299. <title>Clients</title>
  300. <para>
  301. Clients are the interface which bridges a user or external tool into
  302. the Zend_Tool_Framework system. Clients can come in all shapes and
  303. sizes: RPC endpoints, Command Line Interface, or even a web
  304. interface. Zend_Tool has implemented the command line interface as
  305. the default interface for interacting with the Zend_Tool_Framework
  306. system.
  307. </para>
  308. <para>
  309. To implement a client, one would need to extend the following
  310. abstract class:
  311. </para>
  312. <programlisting role="php"><![CDATA[
  313. abstract class Zend_Tool_Framework_Client_Abstract
  314. {
  315. /**
  316. * This method should be implemented by the client implementation to
  317. * construct and set custom loaders, request and response objects.
  318. *
  319. * (not required, but suggested)
  320. */
  321. protected function _preInit();
  322. /**
  323. * This method should be implemented by the client implementation to parse
  324. * out and setup the request objects action, provider and parameter
  325. * information.
  326. */
  327. abstract protected function _preDispatch();
  328. /**
  329. * This method should be implemented by the client implementation to take
  330. * the output of the response object and return it (in an client specific
  331. * way) back to the Tooling Client.
  332. *
  333. * (not required, but suggested)
  334. */
  335. abstract protected function _postDispatch();
  336. }
  337. ]]></programlisting>
  338. <para>
  339. As you can see, there is 1 method required to fulfill the needs of a
  340. client (two othres suggested), the initialization, prehandling and post handling. For a
  341. more in depth study of how the command line client works, please see
  342. <ulink url="http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Tool/Framework/Client/Console.php">source code</ulink>.
  343. </para>
  344. </sect2>
  345. </sect1>