Config_Lite::read PHP Method

read() public method

this method uses the native PHP function parse_ini_file behind the scenes.
public read ( string $filename = null, integer $mode = INI_SCANNER_NORMAL ) : Config_Lite
$filename string Filename
$mode integer INI_SCANNER_NORMAL | INI_SCANNER_RAW
return Config_Lite
    public function read($filename = null, $mode = INI_SCANNER_NORMAL)
    {
        if (null === $filename) {
            $filename = $this->filename;
        } else {
            $this->filename = $filename;
        }
        if (!file_exists($filename)) {
            throw new Config_Lite_Exception_Runtime('file not found: ' . $filename);
        }
        if (!is_readable($filename)) {
            throw new Config_Lite_Exception_Runtime('file not readable: ' . $filename);
        }
        $this->sections = parse_ini_file($filename, $this->processSections, $mode);
        if (false === $this->sections) {
            throw new Config_Lite_Exception_Runtime('failure, can not parse the file: ' . $filename);
        }
        return $this;
    }

Usage Example

コード例 #1
0
ファイル: PEARConfig_Lite.php プロジェクト: phpMussel/extras
<?php

require_once 'Config/Lite.php';
$config = new Config_Lite();
// read config file
$config->read('phpmussel.ini');
// get value from config file
var_dump($config->getBool('general', 'cleanup'));
var_dump($config->getBool('general', 'disable_cli'));
// set value in config file to false
$config->set('general', 'cleanup', false);
$config->set('general', 'disable_cli', true);
// get current value (not yet saved to the config file)
var_dump($config->getBool('general', 'cleanup'));
var_dump($config->getBool('general', 'disable_cli'));
// save new value to config file
$config->save();
// read updated config file
$config->read('phpmussel.ini');
// get saved value from config file
var_dump($config->read('phpmussel.ini')->getBool('general', 'cleanup'));
var_dump($config->read('phpmussel.ini')->getBool('general', 'disable_cli'));