From 5d488c1c087bffe403fda2fd28408e41f8cb10b5 Mon Sep 17 00:00:00 2001
From: Grzegorz Rola <grola@seostudio.pl>
Date: Fri, 22 Mar 2019 07:13:05 +0000
Subject: [PATCH] Feature/log context

---
 src/Client/ApiClientOptions.php         | 5 +++++
 src/Client/ClientFactory.php            | 4 +++-
 src/Client/ClientImplementation.php     | 4 +++-
 tests/unit/Client/TestClientFactory.php | 4 ++++
 4 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/Client/ApiClientOptions.php b/src/Client/ApiClientOptions.php
index 808f292..34d1683 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 81ad8aa..0cc058e 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 feaeb75..f948bec 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 83dc5a9..553524d 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);
-- 
GitLab