Bluz\Config\Config::getData PHP Method

getData() public method

Return configuration by key
public getData ( string | null $key = null, string | null $section = null ) : array | mixed
$key string | null Key of config
$section string | null Section of config
return array | mixed
    public function getData($key = null, $section = null)
    {
        // configuration is missed
        if (is_null($this->config)) {
            throw new ConfigException('System configuration is missing');
        }
        // return all configuration
        if (is_null($key)) {
            return $this->config;
        }
        // return part of configuration
        if (isset($this->config[$key])) {
            // return section of configuration
            if (!is_null($section)) {
                return $this->config[$key][$section] ?? null;
            } else {
                return $this->config[$key];
            }
        } else {
            return null;
        }
    }

Usage Example

Esempio n. 1
0
 /**
  * @covers Bluz\Config\Config::getData
  */
 public function testGetDataBySubSection()
 {
     $this->config->setPath($this->path);
     $this->config->setEnvironment('testing');
     $this->config->init();
     $this->assertEquals(1, $this->config->getData('application', 'section1'));
 }