src/Config.php
public function get(string $key, $default = null)
    {
        // 1. split keys
        $keys = explode(".", $key);
        
        // 2. locate file
        $config_file = $this->context_directory . DIRECTORY_SEPARATOR . array_shift($keys) . ".php";
        
        // 3. load file contents
        if (!isset($this->config_content[$config_file])) {
            if (!is_file($config_file)) {
                throw new \Exception("Config file was not found: " . $config_file);
            }
            $config_content = require($config_file);
        } else {
            $config_content = $this->config_content[$config_file];
        }
        
        // 4. locate desired key
        try {
            return $this->getNestedVar($config_content, $keys);
        } catch (\Exception $e) {
            return $default; // fallback if unable to locate desired key
        }
        
    }
public function get(string $key, $default = null)
    {
        // 1. split keys
        $keys = explode(".", $key);
        
        // 2. locate file
        $config_file = $this->context_directory . DIRECTORY_SEPARATOR . array_shift($keys) . ".php";
        
        // 3. load file contents
        if (!isset($this->config_content[$config_file])) {
            if (!is_file($config_file)) {
                throw new \Exception("Config file was not found: " . $config_file);
            }
            $config_content = require($config_file);
        } else {
            $config_content = $this->config_content[$config_file];
        }
        
        // 4. locate desired key
        try {
            return $this->getNestedVar($config_content, $keys);
        } catch (\Exception $e) {
            return $default; // fallback if unable to locate desired key
        }
        
    }
public function get ( string $ key , $ default = null ) { // 1. split keys $ keys = explode ( "." , $ key ) ; // 2. locate file $ config_file = $ this -> context_directory . DIRECTORY_SEPARATOR . array_shift ( $ keys ) . ".php" ; // 3. load file contents if ( ! isset ( $ this -> config_content [ $ config_file ] ) ) { if ( ! is_file ( $ config_file ) ) { throw new \ Exception ( "Config file was not found: " . $ config_file ) ; } $ config_content = require ( $ config_file ) ; } else { $ config_content = $ this -> config_content [ $ config_file ] ; } // 4. locate desired key try { return $ this -> getNestedVar ( $ config_content , $ keys ) ; } catch ( \ Exception $ e ) { return $ default ; // fallback if unable to locate desired key } }
get config value or fallback gracefully


@param string $key
@param null   $default

@throws \Exception

@return mixed|null
get config value or fallback gracefully