Phergie_Config::read PHP Method

read() public method

Includes a specified PHP configuration file and incorporates its return value (which should be an associative array) into the current configuration settings.
public read ( string $file ) : Phergie_Config
$file string Path to the file to read
return Phergie_Config Provides a fluent interface
    public function read($file)
    {
        if (!file_exists($file)) {
            throw new Phergie_Config_Exception('File "' . $file . '" does not exist', Phergie_Config_Exception::ERR_FILE_NOT_FOUND);
        }
        if (!is_readable($file)) {
            throw new Phergie_Config_Exception('File "' . $file . '" cannot be read', Phergie_Config_Exception::ERR_FILE_NOT_READABLE);
        }
        $settings = (include $file);
        if (!is_array($settings)) {
            throw new Phergie_Config_Exception('File "' . $file . '" does not return an array', Phergie_Config_Exception::ERR_ARRAY_NOT_RETURNED);
        }
        $this->files[$file] = array_keys($settings);
        $this->settings += $settings;
        return $this;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Returns the entire configuration in use or the value of a specific 
  * configuration setting.
  *
  * @param string $index Optional index of a specific configuration 
  *        setting for which the corresponding value should be returned
  *
  * @return mixed Value corresponding to $index or the entire 
  *         configuration if $index is not specified
  */
 public function getConfig($index = null)
 {
     if (empty($this->config)) {
         $this->config = new Phergie_Config();
         $this->config->read('Settings.php');
     }
     if ($index !== null) {
         return $this->config[$index];
     }
     return $this->config;
 }
All Usage Examples Of Phergie_Config::read