예제 #1
0
 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']);
 }
예제 #2
0
 /**
  * @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;
 }
예제 #3
0
 /**
  * @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);
 }
예제 #4
0
 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);
 }
예제 #5
0
 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);
 }
예제 #6
0
 public function testIsDebug()
 {
     $this->assertTrue($this->cfg1->isDebug());
     $this->assertFalse($this->cfg2->isDebug());
     $this->assertFalse($this->cfg3->isDebug());
 }
예제 #7
0
 protected function __construct($sConfigFile)
 {
     parent::__construct(parse_ini_file($sConfigFile));
 }
예제 #8
0
 public function testHetNotExistingSimpleValue()
 {
     $config = new ArrayConfig([]);
     $result = $config->hasValue('dummy');
     $this->assertFalse($result);
 }