Skip to content

Commit 041b1a6

Browse files
committed
Allow instantiation with url string.
1 parent 1257f07 commit 041b1a6

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/Denpa/Bitcoin/Client.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ class Client
2727
/**
2828
* Class constructor.
2929
*
30-
* @param array $config
30+
* @param mixed $config
3131
*
3232
* @return void
3333
*/
34-
public function __construct(array $config = [])
34+
public function __construct($config = [])
3535
{
3636
// init defaults
37-
$config = $this->defaultConfig($this->expandUrl($config));
37+
$config = $this->defaultConfig($this->parseUrl($config));
3838

3939
// construct client
4040
$this->client = new GuzzleHttp([
@@ -249,20 +249,19 @@ protected function defaultConfig(array $config = [])
249249
/**
250250
* Expand URL config into components.
251251
*
252-
* @param array $param
252+
* @param mixed $config
253253
*
254254
* @return array
255255
*/
256-
protected function expandUrl(array $config)
256+
protected function parseUrl($config)
257257
{
258-
if (isset($config['url'])) {
259-
$parts = parse_url($config['url']);
260-
261-
foreach (['scheme', 'host', 'port', 'user', 'pass'] as $setting) {
262-
if (isset($parts[$setting])) {
263-
$config[$setting] = $parts[$setting];
264-
}
258+
if (is_string($config)) {
259+
$parts = parse_url($config);
260+
if (!$parts) {
261+
throw new ClientException('Invalid url');
265262
}
263+
264+
return $parts;
266265
}
267266

268267
return $config;

tests/Denpa/Bitcoin/ClientTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function setUp()
6969
*/
7070
public function testUrlExpander($url, $scheme, $host, $port, $user, $pass)
7171
{
72-
$bitcoind = new Client(['url' => $url]);
72+
$bitcoind = new Client($url);
7373

7474
$this->assertInstanceOf(Client::class, $bitcoind);
7575

@@ -108,7 +108,7 @@ public function urlProvider()
108108
*/
109109
public function testClientSetterGetter()
110110
{
111-
$bitcoind = new Client(['url' => 'http://old_client.org']);
111+
$bitcoind = new Client('http://old_client.org');
112112
$this->assertInstanceOf(Client::class, $bitcoind);
113113

114114
$base_uri = $bitcoind->getConfig('base_uri');

0 commit comments

Comments
 (0)