public function testOffsetSetAfterRestrict() { $config = new ArrayConfig(['a.a' => 'a.a', 'b.a' => 'b.a']); $restrictedConfig = $config->restrict('a'); $this->assertSame('a.a', $config['a.a']); $this->assertSame('a.a', $restrictedConfig['a']); $restrictedConfig['a'] = 'a.a.2'; $this->assertSame('a.a.2', $config['a.a']); $this->assertSame('a.a.2', $restrictedConfig['a']); }
/** * @return array */ public function getArrayCopy() { $result = []; foreach (parent::getArrayCopy() as $key => $value) { if (strpos($key, $this->getRestriction()) === 0) { $result[str_replace($this->getRestriction(), '', $key)] = $value; } } return $result; }
/** * @param string $configFile * @throws \Exception */ public function __construct($configFile) { if (!file_exists($configFile)) { throw new \Exception('The file "' . $configFile . '" doesn\'t exist!'); } $this->configFile = $configFile; $configArray = json_decode(file_get_contents($configFile), true); if (!is_array($configArray)) { throw new \Exception('Wrong format given!'); } parent::__construct($configArray); }
public function __construct($configFile) { if (!file_exists($configFile)) { throw new \Exception('The file "' . $configFile . '" doesn\'t exist!'); } $this->configFile = $configFile; $configArray = (require $this->configFile); if (!is_array($configArray)) { throw new \Exception('no array given!'); } parent::__construct($configArray); }
protected function __construct($sGPC) { $aConfig = array(); switch ($sGPC) { case 'get': $aConfig = $_GET; break; case 'post': $aConfig = $_POST; break; case 'cookie': $aConfig = $_COOKIE; break; default: throw new InvalidArgumentException('Invalid config mode'); } parent::__construct($aConfig); }
public function testIsDebug() { $this->assertTrue($this->cfg1->isDebug()); $this->assertFalse($this->cfg2->isDebug()); $this->assertFalse($this->cfg3->isDebug()); }
protected function __construct($sConfigFile) { parent::__construct(parse_ini_file($sConfigFile)); }
public function testHetNotExistingSimpleValue() { $config = new ArrayConfig([]); $result = $config->hasValue('dummy'); $this->assertFalse($result); }