Zend_Config-TheoryOfOperation.xml 5.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.config.theory_of_operation">
  4. <title>Theory of Operation</title>
  5. <para>
  6. Configuration data are made accessible to the <classname>Zend_Config</classname> constructor
  7. through an associative array, which may be multi-dimensional, in order to support
  8. organizing the data from general to specific. Concrete adapter classes
  9. adapt configuration data from storage to produce the associative array for the
  10. <classname>Zend_Config</classname> constructor. User scripts may provide such arrays
  11. directly to the <classname>Zend_Config</classname> constructor, without using an adapter
  12. class, since it may be appropriate to do so in certain situations.
  13. </para>
  14. <para>
  15. Each configuration data array value becomes a property of the
  16. <classname>Zend_Config</classname> object. The key is used as the property name. If a value
  17. is itself an array, then the resulting object property is created as a new
  18. <classname>Zend_Config</classname> object, loaded with the array data. This occurs
  19. recursively, such that a hierarchy of configuration data may be created with any number of
  20. levels.
  21. </para>
  22. <para>
  23. <classname>Zend_Config</classname> implements the <code>Countable</code> and
  24. <code>Iterator</code> interfaces in order to facilitate simple access to configuration data.
  25. Thus, one may use the <ulink url="http://php.net/count"><code>count()</code></ulink>
  26. function and PHP constructs such as
  27. <ulink url="http://php.net/foreach"><code>foreach</code></ulink> with
  28. <classname>Zend_Config</classname> objects.
  29. </para>
  30. <para>
  31. By default, configuration data made available through <classname>Zend_Config</classname> are
  32. read-only, and an assignment (e.g., <code>$config->database->host = 'example.com'</code>)
  33. results in a thrown exception. This default behavior may be overridden through the
  34. constructor, however, to allow modification of data values. Also, when modifications are
  35. allowed, <classname>Zend_Config</classname> supports unsetting of values (i.e.
  36. <code>unset($config->database->host);</code>). The <code>readOnly()</code> method can be
  37. used to determine if modifications to a given <classname>Zend_Config</classname> object are
  38. allowed and the <code>setReadOnly()</code> method can be used to stop any further
  39. modifications to a <classname>Zend_Config</classname> object that was created allowing
  40. modifications.
  41. <note>
  42. <para>
  43. It is important not to confuse such in-memory modifications with saving
  44. configuration data out to specific storage media. Tools for creating and modifying
  45. configuration data for various storage media are out of scope with respect to
  46. <classname>Zend_Config</classname>. Third-party open source solutions are readily
  47. available for the purpose of creating and modifying configuration data for various
  48. storage media.
  49. </para>
  50. </note>
  51. </para>
  52. <para>
  53. Adapter classes inherit from the <classname>Zend_Config</classname> class since they utilize
  54. its functionality.
  55. </para>
  56. <para>
  57. The <classname>Zend_Config</classname> family of classes enables configuration data to be
  58. organized into sections. <classname>Zend_Config</classname> adapter objects may be loaded
  59. with a single specified section, multiple specified sections, or all sections
  60. (if none are specified).
  61. </para>
  62. <para>
  63. <classname>Zend_Config</classname> adapter classes support a single inheritance model that
  64. enables configuration data to be inherited from one section of configuration data
  65. into another. This is provided in order to reduce or eliminate the need for
  66. duplicating configuration data for different purposes. An inheriting section
  67. may also override the values that it inherits through its parent section.
  68. Like PHP class inheritance, a section may inherit from a parent section,
  69. which may inherit from a grandparent section, and so on, but multiple inheritance
  70. (i.e., section C inheriting directly from parent sections A and B) is not supported.
  71. </para>
  72. <para>
  73. If you have two <classname>Zend_Config</classname> objects, you can merge them into a single
  74. object using the <code>merge()</code> function. For example, given
  75. <varname>$config</varname> and <varname>$localConfig</varname>, you can merge data from
  76. <varname>$localConfig</varname> to <varname>$config</varname> using
  77. <code>$config->merge($localConfig);</code>. The items in <varname>$localConfig</varname>
  78. will override any items with the same name in <varname>$config</varname>.
  79. <note>
  80. <para>
  81. The <classname>Zend_Config</classname> object that is performing the merge must have
  82. been constructed to allow modifications, by passing <constant>TRUE</constant> as the
  83. second parameter of the constructor. The <code>setReadOnly()</code> method can then
  84. be used to prevent any further modifications after the merge is complete.
  85. </para>
  86. </note>
  87. </para>
  88. </sect1>
  89. <!--
  90. vim:se ts=4 sw=4 et:
  91. -->