Zend_Config_Ini.xml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 INI format and read them in the application by using nested object property syntax.
  8. The INI format is specialized to provide both the ability to have a hierarchy of
  9. configuration data keys and inheritance between configuration data sections. Configuration
  10. data hierarchies are supported by separating the keys with the dot or period character
  11. ("<emphasis>.</emphasis>"). A section may extend or inherit from another section by
  12. following the section name with a colon character ("<emphasis>:</emphasis>) and the name of
  13. 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. PHP function. Please review this documentation to be aware of its specific behaviors,
  21. which propagate to <classname>Zend_Config_Ini</classname>, such as how the special
  22. values of "<constant>TRUE</constant>", "<constant>FALSE</constant>", "yes", "no",
  23. 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 <emphasis>'nestSeparator'</emphasis> when constructing
  32. the <classname>Zend_Config_Ini</classname> object. For example:
  33. <programlisting language="php"><![CDATA[
  34. $options['nestSeparator'] = ':';
  35. $config = new Zend_Config_Ini('/path/to/config.ini',
  36. 'staging',
  37. $options);
  38. ]]></programlisting>
  39. </para>
  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 INI file. In this example there are configuration
  46. data for both a production system and for a staging system. Because the staging system
  47. configuration data are very similar to those for production, the staging section
  48. inherits from the production section. In this case, the decision is arbitrary and could
  49. have been written conversely, with the production section inheriting from the staging
  50. section, though this may not be the case for more complex situations. Suppose, then,
  51. 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 INI file. It is a simple matter to load these data by specifying the INI file and
  73. 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 INI file to load.</entry>
  95. </row>
  96. <row>
  97. <entry><varname>$section</varname></entry>
  98. <entry>The [section] within the ini file that is to be loaded. Setting
  99. this parameter to null will load all sections. Alternatively, an
  100. array of section names may be supplied to load multiple sections.</entry>
  101. </row>
  102. <row>
  103. <entry><varname>$options = false</varname></entry>
  104. <entry>Options array. The following keys are supported:
  105. <itemizedlist>
  106. <listitem>
  107. <para>
  108. <emphasis>allowModifications</emphasis>: Set to true to allow
  109. subsequent modification of loaded file. Defaults to false
  110. </para>
  111. </listitem>
  112. <listitem>
  113. <para>
  114. <emphasis>nestSeparator</emphasis>: Set to the character to be
  115. used as the nest separator. Defaults to "."
  116. </para>
  117. </listitem>
  118. </itemizedlist>
  119. </entry>
  120. </row>
  121. </tbody>
  122. </tgroup>
  123. </table>
  124. </note>
  125. </sect1>
  126. <!--
  127. vim:se ts=4 sw=4 et:
  128. -->