Zend_Config_Ini.xml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.config.adapters.ini">
  4. <title>Zend_Config_Ini</title>
  5. <para>
  6. <classname>Zend_Config_Ini</classname> enables developers to store configuration data in a
  7. familiar <acronym>INI</acronym> format and read them in the application by using nested
  8. object property syntax. The <acronym>INI</acronym> format is specialized to provide both
  9. the ability to have a hierarchy of configuration data keys and inheritance between
  10. configuration data sections. Configuration data hierarchies are supported by separating the
  11. keys with the dot or period character ("<emphasis>.</emphasis>"). A section may extend or
  12. inherit from another section by following the section name with a colon character
  13. ("<emphasis>:</emphasis>) and the name of the section from which data are to be inherited.
  14. </para>
  15. <note>
  16. <title>Parsing the INI File</title>
  17. <para>
  18. <classname>Zend_Config_Ini</classname> utilizes the <ulink
  19. url="http://php.net/parse_ini_file"><methodname>parse_ini_file()</methodname></ulink>
  20. <acronym>PHP</acronym> function. Please review this documentation to be aware of its
  21. specific behaviors, which propagate to <classname>Zend_Config_Ini</classname>, such as
  22. how the special values of "<constant>TRUE</constant>", "<constant>FALSE</constant>",
  23. "yes", "no", and "<constant>NULL</constant>" are handled.
  24. </para>
  25. </note>
  26. <note>
  27. <title>Key Separator</title>
  28. <para>
  29. By default, the key separator character is the period character
  30. ("<emphasis>.</emphasis>"). This can be changed, however, by changing the
  31. <varname>$options</varname> key <property>nestSeparator</property> when constructing
  32. the <classname>Zend_Config_Ini</classname> object. For example:
  33. </para>
  34. <programlisting language="php"><![CDATA[
  35. $options['nestSeparator'] = ':';
  36. $config = new Zend_Config_Ini('/path/to/config.ini',
  37. 'staging',
  38. $options);
  39. ]]></programlisting>
  40. </note>
  41. <example id="zend.config.adapters.ini.example.using">
  42. <title>Using Zend_Config_Ini</title>
  43. <para>
  44. This example illustrates a basic use of <classname>Zend_Config_Ini</classname> for
  45. loading configuration data from an <acronym>INI</acronym> file. In this example there
  46. are configuration data for both a production system and for a staging system. Because
  47. the staging system configuration data are very similar to those for production, the
  48. staging section inherits from the production section. In this case, the decision is
  49. arbitrary and could have been written conversely, with the production section
  50. inheriting from the staging section, though this may not be the case for more complex
  51. situations. Suppose, then, that the following configuration data are contained in
  52. <filename>/path/to/config.ini</filename>:
  53. </para>
  54. <programlisting language="ini"><![CDATA[
  55. ; Production site configuration data
  56. [production]
  57. webhost = www.example.com
  58. database.adapter = pdo_mysql
  59. database.params.host = db.example.com
  60. database.params.username = dbuser
  61. database.params.password = secret
  62. database.params.dbname = dbname
  63. ; Staging site configuration data inherits from production and
  64. ; overrides values as necessary
  65. [staging : production]
  66. database.params.host = dev.example.com
  67. database.params.username = devuser
  68. database.params.password = devsecret
  69. ]]></programlisting>
  70. <para>
  71. Next, assume that the application developer needs the staging configuration data from
  72. the <acronym>INI</acronym> file. It is a simple matter to load these data by specifying
  73. the <acronym>INI</acronym> file and the staging section:
  74. </para>
  75. <programlisting language="php"><![CDATA[
  76. $config = new Zend_Config_Ini('/path/to/config.ini', 'staging');
  77. echo $config->database->params->host; // prints "dev.example.com"
  78. echo $config->database->params->dbname; // prints "dbname"
  79. ]]></programlisting>
  80. </example>
  81. <note>
  82. <table id="zend.config.adapters.ini.table">
  83. <title>Zend_Config_Ini Constructor Parameters</title>
  84. <tgroup cols="2">
  85. <thead>
  86. <row>
  87. <entry>Parameter</entry>
  88. <entry>Notes</entry>
  89. </row>
  90. </thead>
  91. <tbody>
  92. <row>
  93. <entry><varname>$filename</varname></entry>
  94. <entry>The <acronym>INI</acronym> file to load.</entry>
  95. </row>
  96. <row>
  97. <entry><varname>$section</varname></entry>
  98. <entry>
  99. The [section] within the <acronym>INI</acronym> file that is to be
  100. loaded. Setting this parameter to <constant>NULL</constant> will load
  101. all sections. Alternatively, an array of section names may be supplied
  102. to load multiple sections.
  103. </entry>
  104. </row>
  105. <row>
  106. <entry>
  107. <varname>$options</varname> (default <constant>FALSE</constant>)
  108. </entry>
  109. <entry>
  110. Options array. The following keys are supported:
  111. <itemizedlist>
  112. <listitem>
  113. <para>
  114. <emphasis><property>allowModifications</property></emphasis>:
  115. Set to <constant>TRUE</constant> to allow subsequent
  116. modification of loaded configuration data in-memory.
  117. Defaults to <constant>NULL</constant>
  118. </para>
  119. </listitem>
  120. <listitem>
  121. <para>
  122. <emphasis><property>nestSeparator</property></emphasis>: Set
  123. to the character to be used as the nest separator. Defaults
  124. to "."
  125. </para>
  126. </listitem>
  127. </itemizedlist>
  128. </entry>
  129. </row>
  130. </tbody>
  131. </tgroup>
  132. </table>
  133. </note>
  134. </sect1>
  135. <!--
  136. vim:se ts=4 sw=4 et:
  137. -->