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)); }
/** * @param string $name * @param $value * @return mixed */ public function set($name, $value) { $this->conf = ArrayUtils::setInArray($this->conf, $name, $value); return $this; }