From 7be9ea68c7c8988c86f95c2c39ccce1eb39f9353 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 5 Apr 2014 10:36:18 +0200 Subject: [PATCH] Added Config::getPath() and Config::setPath() --- src/pocketmine/utils/Config.php | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/pocketmine/utils/Config.php b/src/pocketmine/utils/Config.php index 4b9245c8f..894a0736d 100644 --- a/src/pocketmine/utils/Config.php +++ b/src/pocketmine/utils/Config.php @@ -248,6 +248,40 @@ class Config{ return $this->config[$k]; } + /** + * @param string $path + * + * @return mixed + */ + public function &getPath($path){ + $currPath =& $this->config; + foreach(explode(".", $path) as $component){ + if(isset($currPath[$component])){ + $currPath =& $currPath[$component]; + }else{ + $currPath = null; + } + } + return $currPath; + } + + /** + * @param string $path + * @param mixed $value + */ + public function &setPath($path, $value){ + $currPath =& $this->config; + $components = explode(".", $path); + $final = array_pop($components); + foreach($components as $component){ + if(!isset($currPath[$component])){ + $currPath[$component] = array(); + } + $currPath =& $currPath[$component]; + } + $currPath[$final] = $value; + } + /** * @param string $k key to be set * @param bool $v value to set key