Config->get() - Added default return argument ($key, $default) #2398

Closed
wants to merge 2 commits into
from

Projects

None yet

4 participants

@TruDan
Contributor
TruDan commented Dec 13, 2014

Similar to in Bukkit, where you can get config values and if it doesn't exist, it returns a preferred default value i.e

$var = $plugin->getConfig()->get("a.node.here",10);
and if "a.node.here" doesnt exist in the config, it will return "10". saves having to do this for each node:

$var = $plugin->getConfig()->get("a.node.here"); $var = ($var === false) ? 10 : $var;

Haven't tested, but it shouldn't break anything?

@TruDan TruDan Config->get() - Added default return argument ($key, $default)
72fdf78
@PEMapModder
Collaborator

Maybe you can return $default directly rather than defining an addition $return.

@TruDan
Contributor
TruDan commented Dec 13, 2014

I thought of that, but wasn't sure if that would give errors, since it is a return-as-reference. (self-taught php, not a pro, yet :P)

@PEMapModder
Collaborator

I'm self-taught too. But since $default isn't accepted with reference, it won't lead to other bugs.

@TruDan TruDan Merge pull request #1 from PocketMine/master
Update to latest dev
55daf1a
@64FF00
Contributor
64FF00 commented Dec 13, 2014

@PEMapModder No one can beat me at all. I AM THE MOST USELESS SELF-TAUGHT PROGRAMMARRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR

@PEMapModder
Collaborator

@TruDan you don't need to merge newest commits from master because they will be merged when the pull request is accepted. You are just making more commits in the history because a merge commit will be made anyway (unless they mergee it from command line).

@64FF00 OK, you are the most useless self-taught programmar and I will be the msot useless self-taught programmer 😝

@TruDan
Contributor
TruDan commented Dec 13, 2014

@PEMapModder I was updating my own fork to have the latest code, since i have my projects set up to my fork as the dependency rather than the pocketmine phar, so i can make edits if needed, like this one.

  • Rookie at pull-requests
@shoghicp
Member

Remember that Config->get("a.node.here") won't work for nested properties, you've to use getNested() and setNested(). I'll implement this on a different patch

@shoghicp shoghicp closed this in 1f9cd6a Dec 15, 2014
@TruDan
Contributor
TruDan commented Dec 15, 2014

I currently use ->get("MySQL.Host") etc and it works fine for:
MySQL:
Host: "localhost"

O.o

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment