<?php
goweb::loadClass('Zend_Config_Ini');
/**
 * Goweb Sitemanager 5 Framework
 *
 * Config
 *
 * @version    5.0.0
 * @category   Goweb
 * @package    Goweb_Config_Ini
 * @author     I&D <dev@goweb.pt>, Pedro Pinto <ppinto@goweb.pt>
 * @copyright  2009 (c) Goweb (http://www.goweb.pt)
 *
 *
 */
class Goweb_Config_Ini extends Zend_Config_Ini {
    public static function load($filename, $section, $allowModifications = false) {
        $cache = Zend_Registry::get('cache');
        if(!$ini_cache = $cache->load(md5(md5_file($filename) . $section))) {

            if (empty($filename)) {
                throw new Goweb_Exception('O ficheiro n&atilde;o este definido');
            }
            if (empty($section)) {
                throw new Goweb_Exception('A secccao n&atilde;o este definida');
            }

            $iniArray = parse_ini_file($filename, true);
            if (!isset($iniArray[$section])) {
                throw new Goweb_Exception("A seccao '$section' n&atilde;o foi encontrada em '$filename'");
            }

            $self = new self($filename, $section, $allowModifications);
            $ini_cache = $self->_processExtends($iniArray, $section);
            $cache->save($ini_cache, md5(md5_file($filename) . $section));
        }
        return $ini_cache;
    }
    
    public function _processExtends($iniArray, $section, $config = array()){
        return $this->_processSection($iniArray, $section, $config);
    }
}