Skip to content

Commit

Permalink
Add global function 'getConfig'
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmerainfo committed Oct 18, 2015
1 parent 05245e3 commit bd7b541
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ echo Config::get('DB_NAME');
echo Config::get('API_KEY');
// output: sdfds6549sdf7SDFD@#$55

// With under any namespace
echo \Config::get('API_KEY');

// call other way from anywhere
getConfig('API_KEY');
getConfig('API_KEY', 'DEFAULT VALUE IF NOT FOUND');

echo Config::get('DUMMY', 'Default Value');
// output: Default Value
// Get default value if key not found in config file
Expand Down
15 changes: 13 additions & 2 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*
*/

class Config
{
class Config {

/**
* store all list of configuration
*
Expand Down Expand Up @@ -122,4 +122,15 @@ private static function readFile($filePath)
// return all lines
return $lines;
}
}

/**
* add `getConfig()` function for configuration call without namespace call
* function can be call from anywhere global
*
*/
if(!function_exists("getConfig")) {
function getConfig($key, $defaultValue = null) {
return Config::get($key, $defaultValue);
}
}

0 comments on commit bd7b541

Please sign in to comment.