Exemple #1
0
 /**
  * @param string $name
  * @return bool
  */
 public function has($name)
 {
     $re = ArrayUtils::hasInArray($this->conf, $name);
     if (!$re && !$this->useCache) {
         foreach ($this->sources as $source) {
             if ($source instanceof IConfigSource) {
                 $re = $source->has($name);
                 if ($re === true) {
                     return true;
                 }
             }
         }
     }
     return $re;
 }
Exemple #2
0
 /**
  * @param string $name
  * @return bool
  */
 public function has($name)
 {
     if (ArrayUtils::hasInArray($this->conf, $name)) {
         return true;
     } else {
         if ($this->redis) {
             $f = $this->getField($name);
             $b = $this->redis->hexists($this->key, $f);
             if ($b) {
                 $v = $this->redis->hget($this->key, $f);
                 $this->conf[$f] = unserialize($v);
                 return ArrayUtils::hasInArray($this->conf, $name);
             }
         }
     }
     return false;
 }
Exemple #3
0
 public function testArrayUtils()
 {
     $arr = ['a' => 'val1', 'b' => ['bb1' => 'val2', 'bb2' => ['bbb1' => 'val3']], 'c' => ['a', 'b', 'c'], 'd' => true, 'e' => ['ee1' => null, 'ee2' => [1, 2]]];
     $tests1 = ['a' => true, 'b' => true, 'b.bb1' => true, 'b.bb2.bbb1' => true, 'b.bb3' => false, 'c' => true, 'c.0' => true, 'c.3' => false, 'd' => true, 'd.a' => false, 'e' => true, 'e.ee1' => true, 'e.ee2.0' => true, 'e.ee3' => false, '.e' => false, 'e.' => false];
     foreach ($tests1 as $t => $exp) {
         $this->assertEquals($exp, \Wwtg99\Config\Common\ArrayUtils::hasInArray($arr, $t), "Test {$t}");
     }
     $tests2 = ['a' => 'val1', 'b.bb1' => 'val2', 'b.bb2.bbb1' => 'val3', 'b.bb3' => null, 'c' => ['a', 'b', 'c'], 'c.1' => 'b', 'd' => true, 'd.a' => null, 'e.ee1' => null, 'e.ee2' => [1, 2], 'e.ee2.0' => 1, 'e.ee3' => null, '.e' => null, 'e.' => null];
     foreach ($tests2 as $t => $exp) {
         $this->assertEquals($exp, \Wwtg99\Config\Common\ArrayUtils::getInArray($arr, $t), "Test {$t}");
     }
     $this->assertEquals('aa', \Wwtg99\Config\Common\ArrayUtils::getInArray($arr, 'f', 'aa'), "Test default value");
     $this->assertEquals(null, \Wwtg99\Config\Common\ArrayUtils::getInArray($arr, 'e.ee1', 'aa'), "Test default value");
     $arr = [];
     $this->assertEquals(['a' => 'val1'], \Wwtg99\Config\Common\ArrayUtils::setInArray($arr, 'a', 'val1'));
     $this->assertEquals(['a' => 'val1'], \Wwtg99\Config\Common\ArrayUtils::setInArray($arr, 'a.aa', 'val2'));
     $this->assertEquals(['a' => 'val1', 'b' => ['bb' => 'val2']], \Wwtg99\Config\Common\ArrayUtils::setInArray($arr, 'b.bb', 'val2'));
     $this->assertEquals(['a' => 'val1', 'b' => ['bb' => 'val2', 'bbb' => [1, 2]]], \Wwtg99\Config\Common\ArrayUtils::setInArray($arr, 'b.bbb', [1, 2]));
     $this->assertEquals(['a' => 'val1', 'b' => ['bb' => 'val2', 'bbb' => [1, 2, 3]]], \Wwtg99\Config\Common\ArrayUtils::setInArray($arr, 'b.bbb.2', 3));
     $this->assertEquals(['a' => 'val1', 'b' => ['bb' => 'val2', 'bbb' => [1, 2, 3]], 'c' => null], \Wwtg99\Config\Common\ArrayUtils::setInArray($arr, 'c', null));
 }
Exemple #4
0
 /**
  * @param string $name
  * @return bool
  */
 public function has($name)
 {
     return ArrayUtils::hasInArray($this->conf, $name);
 }