pocketmine\utils\Config::getNested PHP Method

getNested() public method

public getNested ( $key, mixed $default = null ) : mixed
$key
$default mixed
return mixed
    public function getNested($key, $default = null)
    {
        if (isset($this->nestedCache[$key])) {
            return $this->nestedCache[$key];
        }
        $vars = explode(".", $key);
        $base = array_shift($vars);
        if (isset($this->config[$base])) {
            $base = $this->config[$base];
        } else {
            return $default;
        }
        while (count($vars) > 0) {
            $baseKey = array_shift($vars);
            if (is_array($base) and isset($base[$baseKey])) {
                $base = $base[$baseKey];
            } else {
                return $default;
            }
        }
        return $this->nestedCache[$key] = $base;
    }

Usage Example

Exemplo n.º 1
0
 public function getProperty($variable, $defaultValue = null)
 {
     if (!array_key_exists($variable, $this->propertyCache)) {
         $v = getopt("", ["{$variable}::"]);
         if (isset($v[$variable])) {
             $this->propertyCache[$variable] = $v[$variable];
         } else {
             $this->propertyCache[$variable] = $this->properties->getNested($variable);
         }
     }
     return $this->propertyCache[$variable] === null ? $defaultValue : $this->propertyCache[$variable];
 }
All Usage Examples Of pocketmine\utils\Config::getNested