From ec7b91aae3fe76f12b1c0308bfd0d4c0b08fcdea Mon Sep 17 00:00:00 2001 From: Jeroen van Leusden Date: Thu, 4 Mar 2021 08:31:23 +0100 Subject: [PATCH] Use factory class to create AkeneoPimClientBuilder instance --- Helper/Authenticator.php | 37 ++++++++++------------- Model/AkeneoPimClientBuilderFactory.php | 40 +++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 22 deletions(-) create mode 100644 Model/AkeneoPimClientBuilderFactory.php diff --git a/Helper/Authenticator.php b/Helper/Authenticator.php index fe629194..845114bc 100644 --- a/Helper/Authenticator.php +++ b/Helper/Authenticator.php @@ -1,10 +1,12 @@ configHelper = $configHelper; + $this->clientBuilderFactory = $clientBuilderFactory; } /** @@ -46,24 +46,17 @@ public function __construct( */ public function getAkeneoApiClient() { - /** @var string $baseUri */ $baseUri = $this->configHelper->getAkeneoApiBaseUrl(); - /** @var string $clientId */ $clientId = $this->configHelper->getAkeneoApiClientId(); - /** @var string $secret */ $secret = $this->configHelper->getAkeneoApiClientSecret(); - /** @var string $username */ $username = $this->configHelper->getAkeneoApiUsername(); - /** @var string $password */ $password = $this->configHelper->getAkeneoApiPassword(); if (!$baseUri || !$clientId || !$secret || !$username || !$password) { return false; } - /** @var AkeneoPimClientBuilder $akeneoClientBuilder */ - $akeneoClientBuilder = new AkeneoPimClientBuilder($baseUri); - + $akeneoClientBuilder = $this->clientBuilderFactory->create(['baseUri' => $baseUri]); $akeneoClientBuilder->setHttpClient(new Client()); $akeneoClientBuilder->setStreamFactory(new StreamFactory()); $akeneoClientBuilder->setRequestFactory(new RequestFactory()); diff --git a/Model/AkeneoPimClientBuilderFactory.php b/Model/AkeneoPimClientBuilderFactory.php new file mode 100644 index 00000000..0ad3c1ed --- /dev/null +++ b/Model/AkeneoPimClientBuilderFactory.php @@ -0,0 +1,40 @@ +objectManager = $objectManager; + $this->instanceName = $instanceName; + } + + /** + * Create class instance with specified parameters. + * + * @param array $data + * + * @return AkeneoPimClientBuilder|AkeneoPimEnterpriseClientBuilder + */ + public function create(array $data = []) + { + return $this->objectManager->create($this->instanceName, $data); + } +}