monero-integrations / monerophp

Monero PHP library + JsonRPC Client
MIT License
118 stars 76 forks source link

Allow daemon and wallet RPC classes to be optionally constructed with parameters passed in as objects/dictionaries (associative arrays) #71

Closed sneurlax closed 6 years ago

sneurlax commented 6 years ago

This pull request adds the optional (backwards-compatible) ability for the wallet and daemon RPC classes to be initialized with/parameters passed in as objects/dictionaries (associative arrays.) After this pull request, RPC classes can be initialized in any of the following ways:

$daemonRPC = new daemonRPC('127.0.0.1', 28082);
$daemonRPC = new daemonRPC(['host' => '127.0.0.1', 'port' => 28082]);

or

$daemonRPC = new daemonRPC(['user' => 'username', 'password' => 'passphrase']);

The last example demonstrates how parameters can be passed in in any order or combination, with parameters using their default values if they're not defined.

This pull request isn't necessary at the moment but it does add the capability needed to pass in ['autoconnect' => true], which is the next functionality I'm adding (see https://github.com/sneurlax/moneronodejs/commit/9f17be53cf43e9e1136536d5527b738af330a3e5 for the autoconnect functionality I'm going to port over here.)

This is optional and backwards-compatible, ie. nobody has to change what they're doing now; all current code will continue working as normal.

serhack commented 6 years ago

Could we merge it @sneurlax ?

sneurlax commented 6 years ago

I've been using this for awhile. You may want to test it, but I really prefer it, honestly. Instead of looking up the expected order, you can just provide them in whatever order you want, and leave out the ones you don't want to set--but the old method still works. Win-win.