Zend_Tool_Framework-Architecture.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 15617 -->
  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 language="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 language="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 language="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 language="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 language="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. Die _getFiles() Methode sollte ein Array von Dateien zurückgeben (absolute Pfade). Der
  123. mit ZF ausgelieferte Loader wird IncludePath Loader genannt. Standardmäßig verwendet
  124. das Tooling Framework einen Loader der auf dem Include Pfad basiert um Dateien zu
  125. finden die Provider oder Manifest Metadaten Objekte enthalten können.
  126. Zend_Tool_Framework_Loader_IncludePathLoader sucht, ohne irgendeine Option, nach
  127. Dateien im Include Pfad die mit Mainfest.php, Tool.php oder Provider.php enden. Sobald
  128. Sie gefunden wurden, werden Sie (durch die load() Methode von
  129. Zend_Tool_Framework_Loader_Abstract) getestet um zu erkennen ob Sie irgendeines der
  130. unterstützten Interfaces implementieren. Wenn Sie das tun, wird eine Instanz der
  131. gefundenen Klasse instanziiert, und dann dem richtigen Repository angehängt.
  132. </para>
  133. <programlisting language="php"><![CDATA[
  134. class Zend_Tool_Framework_Loader_IncludePathLoader
  135. extends Zend_Tool_Framework_Loader_Abstract
  136. {
  137. protected $_filterDenyDirectoryPattern = '.*(/|\\\\).svn';
  138. protected $_filterAcceptFilePattern = '.*(?:Manifest|Provider)\.php$';
  139. protected function _getFiles()
  140. {
  141. /** ... */
  142. }
  143. }
  144. ]]></programlisting>
  145. <para>
  146. As you can see, the IncludePath loader will search all include_paths
  147. for the files that match the $_filterAcceptFilePattern and NOT match
  148. the $_filterDenyDirectoryPattern.
  149. </para>
  150. </sect2>
  151. <sect2 id="zend.tool.framework.architecture.manifests">
  152. <title>Manifests</title>
  153. <para>
  154. In short, the Manifest shall contain specific or arbitrary metadata
  155. that is useful to any provider or client, as well as be responsible
  156. for loading any additional providers into the provider repository.
  157. </para>
  158. <para>
  159. To introduce metadata into the manifest repository, all one must do
  160. is implement the empty Zend_Tool_Framework_Manifest_Interface, and
  161. provide a getMetadata() method which shall return an array of
  162. objects that implement Zend_Tool_Framework_Manifest_Metadata.
  163. </para>
  164. <programlisting language="php"><![CDATA[
  165. interface Zend_Tool_Framework_Manifest_Interface
  166. {
  167. public function getMetadata();
  168. }
  169. ]]></programlisting>
  170. <para>
  171. Metadata objects are loaded (by a loader defined below) into the
  172. Manfiest Repository (Zend_Tool_Framework_Manifest_Repository).
  173. Manifests will be processed after all Providers have been found a
  174. loaded into the provider repository. This shall allow Manifests to
  175. created Metadata objects based on what is currently inside the
  176. provider repository.
  177. </para>
  178. <para>
  179. There are a few different metadata classes that can be used to
  180. describe metadata. The Zend_Tool_Framework_Manifest_Metadata is the
  181. base metadata object. As you can see by the following code snippet,
  182. the base metadata class is fairly lightweight and abstract in
  183. nature:
  184. </para>
  185. <programlisting language="php"><![CDATA[
  186. class Zend_Tool_Framework_Manifest_Basic
  187. {
  188. protected $_type = 'Global';
  189. protected $_name = null;
  190. protected $_value = null;
  191. protected $_reference = null;
  192. public function getType();
  193. public function getName();
  194. public function getValue();
  195. public function getReference();
  196. /** ... */
  197. }
  198. ]]></programlisting>
  199. <para>
  200. There are other built in metadata classes as well for describing
  201. more specialized metadata: ActionMetadata and ProviderMetadata.
  202. These classes will help you describe in more detail metadata that is
  203. specific to either actions or providers, and the reference is
  204. expected to be a reference to an action or a provider respectively.
  205. These classes are described in the follow code snippet.
  206. </para>
  207. <programlisting language="php"><![CDATA[
  208. class Zend_Tool_Framework_Manifest_ActionMetadata
  209. extends Zend_Tool_Framework_Manifest_Metadata
  210. {
  211. protected $_type = 'Action';
  212. protected $_actionName = null;
  213. public function getActionName();
  214. /** ... */
  215. }
  216. class Zend_Tool_Framework_Manifest_ProviderMetadata
  217. extends Zend_Tool_Framework_Manifest_Metadata
  218. {
  219. protected $_type = 'Provider';
  220. protected $_providerName = null;
  221. protected $_actionName = null;
  222. protected $_specialtyName = null;
  223. public function getProviderName();
  224. public function getActionName();
  225. public function getSpecialtyName();
  226. /** ... */
  227. }
  228. ]]></programlisting>
  229. <para>
  230. 'Type' in these classes is used to describe the type of metadata the
  231. object is responsible for. In the cases of the ActionMetadata, the
  232. type would be 'Action', and conversely in the case of the
  233. ProviderMetadata the type is 'Provider'. These metadata types will
  234. also include additional structured information about both the
  235. "thing" they are describing as well as the object (the
  236. ->getReference()) they are referencing with this new metadata.
  237. </para>
  238. <para>
  239. In order to create your own metadata type, all one must do is extend
  240. the base Zend_Tool_Framework_Manifest_Metadata class and return
  241. these new metadata objects via a local Manifest class/object. These
  242. user based classes will live in the Manifest Repository
  243. </para>
  244. <para>
  245. Once these metadata objects are in the repository there are then two
  246. different methods that can be used in order to search for them in
  247. the repository.
  248. </para>
  249. <programlisting language="php"><![CDATA[
  250. class Zend_Tool_Framework_Manifest_Repository
  251. {
  252. /**
  253. * To use this method to search, $searchProperties should contain the names
  254. * and values of the key/value pairs you would like to match within the
  255. * manifest.
  256. *
  257. * For Example:
  258. * $manifestRepository->findMetadatas(array(
  259. * 'action' => 'Foo',
  260. * 'name' => 'cliActionName'
  261. * ));
  262. *
  263. * Will find any metadata objects that have a key with name 'action' value
  264. * of 'Foo', AND a key named 'name' value of 'cliActionName'
  265. *
  266. * Note: to either exclude or include name/value pairs that exist in the
  267. * search critera but do not appear in the object, pass a bool value to
  268. * $includeNonExistentProperties
  269. */
  270. public function findMetadatas(Array $searchProperties = array(),
  271. $includeNonExistentProperties = true);
  272. /**
  273. * The following will return exactly one of the matching search criteria,
  274. * regardless of how many have been returned. First one in the manifest is
  275. * what will be returned.
  276. */
  277. public function findMetadata(Array $searchProperties = array(),
  278. $includeNonExistentProperties = true)
  279. {
  280. $metadatas = $this->getMetadatas($searchProperties,
  281. $includeNonExistentProperties);
  282. return array_shift($metadatas);
  283. }
  284. }
  285. ]]></programlisting>
  286. <para>
  287. Looking at the search methods above, the signatures allow for
  288. extremely flexible searching. In order to find a metadata object,
  289. simply pass in an array of matching constraints via an array. If
  290. the data is accessible through the Property accessor (the
  291. getSomething() methods implemented on the metadata object), then it
  292. will be passed back to the user as a "found" metadata object.
  293. </para>
  294. </sect2>
  295. <sect2 id="zend.tool.framework.architecture.clients">
  296. <title>Clients</title>
  297. <para>
  298. Clients are the interface which bridges a user or external tool into
  299. the Zend_Tool_Framework system. Clients can come in all shapes and
  300. sizes: RPC endpoints, Command Line Interface, or even a web
  301. interface. Zend_Tool has implemented the command line interface as
  302. the default interface for interacting with the Zend_Tool_Framework
  303. system.
  304. </para>
  305. <para>
  306. To implement a client, one would need to extend the following
  307. abstract class:
  308. </para>
  309. <programlisting language="php"><![CDATA[
  310. abstract class Zend_Tool_Framework_Client_Abstract
  311. {
  312. /**
  313. * This method should be implemented by the client implementation to
  314. * construct and set custom loaders, request and response objects.
  315. *
  316. * (not required, but suggested)
  317. */
  318. protected function _preInit();
  319. /**
  320. * This method should be implemented by the client implementation to parse
  321. * out and setup the request objects action, provider and parameter
  322. * information.
  323. */
  324. abstract protected function _preDispatch();
  325. /**
  326. * This method should be implemented by the client implementation to take
  327. * the output of the response object and return it (in an client specific
  328. * way) back to the Tooling Client.
  329. *
  330. * (not required, but suggested)
  331. */
  332. abstract protected function _postDispatch();
  333. }
  334. ]]></programlisting>
  335. <para>
  336. As you can see, there is 1 method required to fulfill the needs of a
  337. client (two othres suggested), the initialization, prehandling and post handling. For a
  338. more in depth study of how the command line client works, please see
  339. <ulink url="http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Tool/Framework/Client/Console.php">source code</ulink>.
  340. </para>
  341. </sect2>
  342. </sect1>