Przeglądaj źródła

Extract parse_ini_file() and associated error handling to its own method. Fixes ZF-8652

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20036 44c647ce-9c0f-0410-b52a-842ac1e357ba
rob 16 lat temu
rodzic
commit
238ff9c64d
1 zmienionych plików z 25 dodań i 10 usunięć
  1. 25 10
      library/Zend/Config/Ini.php

+ 25 - 10
library/Zend/Config/Ini.php

@@ -157,24 +157,21 @@ class Zend_Config_Ini extends Zend_Config
 
         $this->_loadedSection = $section;
     }
-
+    
     /**
-     * Load the ini file and preprocess the section separator (':' in the
-     * section name (that is used for section extension) so that the resultant
-     * array has the correct section names and the extension information is
-     * stored in a sub-key called ';extends'. We use ';extends' as this can
-     * never be a valid key name in an INI file that has been loaded using
-     * parse_ini_file().
-     *
+     * Load the INI file from disk using parse_ini_file(). Use a private error
+     * handler to convert any loading errors into a Zend_Config_Exception
+     * 
      * @param string $filename
      * @throws Zend_Config_Exception
      * @return array
      */
-    protected function _loadIniFile($filename)
+    protected function _parseIniFile($filename)
     {
         set_error_handler(array($this, '_loadFileErrorHandler'));
-        $loaded = parse_ini_file($filename, true); // Warnings and errors are suppressed
+        $iniArray = parse_ini_file($filename, true); // Warnings and errors are suppressed
         restore_error_handler();
+        
         // Check if there was a error while loading file
         if ($this->_loadFileErrorStr !== null) {
             /**
@@ -183,7 +180,25 @@ class Zend_Config_Ini extends Zend_Config
             require_once 'Zend/Config/Exception.php';
             throw new Zend_Config_Exception($this->_loadFileErrorStr);
         }
+        
+        return $iniArray;
+    }
 
+    /**
+     * Load the ini file and preprocess the section separator (':' in the
+     * section name (that is used for section extension) so that the resultant
+     * array has the correct section names and the extension information is
+     * stored in a sub-key called ';extends'. We use ';extends' as this can
+     * never be a valid key name in an INI file that has been loaded using
+     * parse_ini_file().
+     *
+     * @param string $filename
+     * @throws Zend_Config_Exception
+     * @return array
+     */
+    protected function _loadIniFile($filename)
+    {
+        $loaded = $this->_parseIniFile($filename);
         $iniArray = array();
         foreach ($loaded as $key => $data)
         {