Skip to content

Commit f33fe4a

Browse files
committed
feat: allow for http adapter param
- Base client class now accepts Http Adapter object as param. - Add http adapter interface
1 parent 5d43100 commit f33fe4a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/recurly/base_client.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ abstract class BaseClient
3131
* In addition to the options managed by BaseClient, it accepts the following options:
3232
* - "region" to define the Data Center connection - defaults to "us";
3333
*/
34-
public function __construct(string $api_key, LoggerInterface $logger = null, array $options = [])
34+
public function __construct(string $api_key, LoggerInterface $logger = null, array $options = [], HttpAdapterInterface $http_adapter = null)
3535
{
3636
$this->_api_key = $api_key;
3737
if (isset($options['region'])) {
@@ -41,6 +41,11 @@ public function __construct(string $api_key, LoggerInterface $logger = null, arr
4141
$this->baseUrl = BaseClient::API_HOSTS[$options['region']];
4242
}
4343

44+
if (is_null($http_adapter)) {
45+
$http_adapter = new HttpAdapter;
46+
}
47+
$this->http = $http_adapter;
48+
4449
$this->http = new HttpAdapter;
4550
if (is_null($logger)) {
4651
$logger = new \Recurly\Logger('Recurly', LogLevel::WARNING);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Recurly;
4+
5+
/**
6+
* @codeCoverageIgnore
7+
*/
8+
interface HttpAdapterInterface
9+
{
10+
public function execute($method, $url, $body, $headers): array;
11+
}

0 commit comments

Comments
 (0)