Skip to content

Instantly share code, notes, and snippets.

@adarwash
Created November 9, 2014 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adarwash/c55bb3318c49f7ef87b2 to your computer and use it in GitHub Desktop.
Save adarwash/c55bb3318c49f7ef87b2 to your computer and use it in GitHub Desktop.
Added ability to read the configuration values in the initialisation file and added comments
<?php
class Config {
//$path is the value that going to be pass thought for exmaple "Config::get('mysql/host')" the part 'mysql/host' will be the path.
public static function get($path = null){
if($path) {
//$config make it easier to write $GLOBALS['config'];
$config = $GLOBALS['config'];
// Explode will read each value in parts using the forward slash for example mysql/host mysql is first part and host is the seconned part.
$path = explode('/', $path);
// For every value in $path will be store in a variable called $bit
foreach($path as $bit){
//This will check if the value is set in the initialisation file (init.php);
if(isset($config[$bit])){
// After the checked if the value isset then it will store value in variable called $config
$config = $config[$bit];
}
}
//This will return the value that is set.
return $config;
}
// If there no value set then i will return false
return false;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment