public function testGetValueByPath() { $c = new StdClass(); $c->d = "This is the value"; $b = new StdClass(); $b->c = $c; $a = new StdClass(); $a->b = $b; $tree = new StdClass(); $tree->a = $a; $this->assertEquals("This is the value", ValueByPath::getValueByPath($tree, "a.b.c.d")); }
/** * Load or reload the configuration from the specified configuration file and template * * @param null|string $configFile An optional path to a JSON file which should be loaded instead of the $configFile defined on instance creation * * @throws JsonException If the configuration file could not be parsed */ public function load($configFile = null) { $this->configData = json_decode(file_get_contents($this->templateFile)); if ($configFile == null) { $configFile = $this->configFile; } if (file_exists($configFile)) { $configData = json_decode(file_get_contents($configFile)); if (!$configData) { throw new JsonException(); } foreach ($this->configData as $name => $itemData) { $itemData->value = ValueByPath::getValueByPath($configData, $name); } } }