public function testSetValueByPath() { $map = ["one" => "a", "two" => ["one" => "a", "two" => ["one" => "a", "two" => "b", "three" => "c"]]]; CMap::setValueByPath($map, "one", "d"); CMap::setValueByPath($map, "two.one", "e"); CMap::setValueByPath($map, "two.two.one", "f"); CMap::setValueByPath($map, "two.two.two", "g"); CMap::setValueByPath($map, "two.two.three", "h"); $this->assertTrue(CMap::valueByPath($map, "one") === "d"); $this->assertTrue(CMap::equals(CMap::valueByPath($map, "two"), ["one" => "e", "two" => ["one" => "f", "two" => "g", "three" => "h"]])); $this->assertTrue(CMap::valueByPath($map, "two.one") === "e"); $this->assertTrue(CMap::equals(CMap::valueByPath($map, "two.two"), ["one" => "f", "two" => "g", "three" => "h"])); $this->assertTrue(CMap::valueByPath($map, "two.two.one") === "f"); $this->assertTrue(CMap::valueByPath($map, "two.two.two") === "g"); $this->assertTrue(CMap::valueByPath($map, "two.two.three") === "h"); }
/** * In a map, modifies the value found by a specified key path. * * @param string $path The key path by which the value is to be found, e.g. "level1key.level2key". * @param mixed $value The new value. * * @return void */ public function setValueByPath($path, $value) { CMap::setValueByPath($this->m_map, $path, $value); }
/** * Sets the value of the application's configuration option specified by a global path. * * @param string $path The global path to the option. * @param mixed $value The new value. * * @return void */ public static function setOption($path, $value) { assert('is_cstring($path)', vs(isset($this), get_defined_vars())); CMap::setValueByPath(self::$ms_config, $path, $value); }