diff --git a/src/Client/ApiClientOptions.php b/src/Client/ApiClientOptions.php index 808f292cc76300f17879b7ea4d9c7ff62d3b4da1..34d16834be5e03f70048e8b6ee650693527585dc 100644 --- a/src/Client/ApiClientOptions.php +++ b/src/Client/ApiClientOptions.php @@ -29,4 +29,9 @@ interface ApiClientOptions extends HttpClientOptions, SerializerOptions */ public function isCachedClient(); + /** + * @return string + */ + public function getApiClientClass(); + } \ No newline at end of file diff --git a/src/Client/ClientFactory.php b/src/Client/ClientFactory.php index 81ad8aa30ed2b52729e11cd02262e95c84277746..0cc058e53f912982e8d6713a51cf4e5eec98e7ab 100644 --- a/src/Client/ClientFactory.php +++ b/src/Client/ClientFactory.php @@ -17,7 +17,9 @@ class ClientFactory $httpClientFactory = new HttpClientFactory(); $serializerFactory = new SerializerFactory(); - $client = new ClientImplementation( + $className = $options->getApiClientClass(); + + $client = new $className( $httpClientFactory->createClient($options), $serializerFactory->createSerializer($options), $options->getLogger(), diff --git a/src/Client/ClientImplementation.php b/src/Client/ClientImplementation.php index feaeb75b00947472676c99209b8aab814a9722f8..f948becc99b953e324c1e5e2c1268333c3e06096 100644 --- a/src/Client/ClientImplementation.php +++ b/src/Client/ClientImplementation.php @@ -18,6 +18,8 @@ class ClientImplementation implements Client, LoggerAwareInterface const DEFAULT_TIMEOUT = 10; + const LIBRARY_LOGIN_CONTEXT = 'wp-api-client'; + /** @var HttpClient */ private $client; @@ -201,7 +203,7 @@ class ClientImplementation implements Client, LoggerAwareInterface protected function getLoggerContext($additional_context = '') { $context = [ - Platform::LIBARY_LOGIN_CONTEXT, + self::LIBRARY_LOGIN_CONTEXT, self::class ]; if ($additional_context !== '') { diff --git a/tests/unit/Client/TestClientFactory.php b/tests/unit/Client/TestClientFactory.php index 83dc5a9c6ed6a4417111e4b2b3f8d6b55c6277e5..553524d74164ba77435805ca91dbc51f0cbd4dcc 100644 --- a/tests/unit/Client/TestClientFactory.php +++ b/tests/unit/Client/TestClientFactory.php @@ -15,6 +15,10 @@ class TestClientFactory extends \PHPUnit\Framework\TestCase private function prepareOptions($isCachedClient = false) { $options = Mockery::mock(\WPDesk\ApiClient\Client\ApiClientOptions::class); + $options->shouldReceive('getApiClientClass') + ->withAnyArgs() + ->andReturn(\WPDesk\ApiClient\Client\ClientImplementation::class); + $options->shouldReceive('getHttpClientClass') ->withAnyArgs() ->andReturn(\WPDesk\HttpClient\Curl\CurlClient::class);