config; if (strpos($key, '.') === false) { if (isset($config->data[$key])) { return $config->data[$key]; } else if ($default !== null) { return $default; } else if ($try) { throw new ConfigException(str_replace(':key', $key, self::ERROR_MESSAGE)); } return NULL; } $keys = explode('.', $key); $parent = $config->data[array_shift($keys)] ?? null; if (empty($parent)) { return $default; } if (empty($keys) || !is_array($parent)) { return $parent; } foreach ($keys as $key) { if (!isset($parent[$key])) { return $parent; } $parent = $parent[$key]; if (empty($keys) || !is_array($parent)) { return $parent; } } return $parent; } /** * @param $key * @param $value * @return mixed * @throws Exception */ public static function set($key, $value) { $config = Snowflake::get()->config; return $config->data[$key] = $value; } /** * @param $key * @param bool $must_not_null * @return bool */ public static function has($key, $must_not_null = false) { $config = Snowflake::get()->config; if (!isset($config->data[$key])) { return false; } $config = $config->data[$key]; if ($must_not_null === false) { return true; } return !empty($config); } /** * @param $name * @param $value */ public function __set($name, $value) { $this->data[$name] = $value; } }