Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CC-33265: Update of the Akeneo HTTP client library to support all latest versions. #24

Merged
Merged
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
fail-fast: false
matrix:
php-versions:
- '7.2'
- '8.1'
- '8.2'

services:
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
php-version: '8.1'
extensions: mbstring, intl, bcmath, pdo_mysql

- name: Composer Install
Expand Down
5 changes: 4 additions & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
build:
environment:
php: '7.2'
php: '8.1'

tests:
override:
- true
dependencies:
override:
- composer self-update

nodes:
analysis:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Build Status](https://scrutinizer-ci.com/g/spryker-eco/akeneo-pim/badges/build.png?b=master)](https://scrutinizer-ci.com/g/spryker-eco/akeneo-pim/build-status/master)
[![Latest Stable Version](https://poser.pugx.org/spryker-eco/akeneo-pim/v/stable.svg)](https://packagist.org/packages/spryker-eco/akeneo-pim)
[![License](https://img.shields.io/github/license/spryker-eco/akeneo-pim.svg?b=master)](https://github.com/spryker-eco/akeneo-pim)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.2-8892BF.svg)](https://php.net/)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.1-8892BF.svg)](https://php.net/)

## Installation

Expand Down
18 changes: 13 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
"description": "AkeneoPim module",
"license": "proprietary",
"require": {
"akeneo/api-php-client": "^1.0.0 || ^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0",
"php": ">=7.2",
"guzzlehttp/guzzle": "^6.0.0 || ^7.0.0",
"akeneo/api-php-client": "^1.0.0 || ^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0",
"php": ">=8.1",
"php-http/httplug": "^1.0.0 || ^2.0.0",
"php-http/promise": "^1.0.0",
"psr/http-client": "^1.0.0",
abitskil marked this conversation as resolved.
Show resolved Hide resolved
"psr/http-message": "^1.0.0 || ^2.0.0",
"spryker/guzzle": "^2.3.0",
"spryker/kernel": "^3.30.0"
},
"require-dev": {
"spryker/code-sniffer": "*"
"phpstan/phpstan": "^1.0.0",
"spryker/code-sniffer": "*",
"spryker/testify": "*"
},
"autoload": {
"psr-4": {
Expand All @@ -26,7 +32,9 @@
"prefer-stable": true,
"scripts": {
"cs-check": "phpcs -p -s --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml src/ tests/",
"cs-fix": "phpcbf -p --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml src/ tests/"
"cs-fix": "phpcbf -p --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml src/ tests/",
"stan": "phpstan analyse -c phpstan.neon -l 8 src/",
"stan-setup": "cp composer.json composer.backup && COMPOSER_MEMORY_LIMIT=-1 composer require --dev phpstan/phpstan:^0.12 && mv composer.backup composer.json"
},
"extra": {
"branch-alias": {
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
parameters:
level: 7
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
- '#Parameter \#1 \$httpClient of method Akeneo\\Pim\\ApiClient\\AkeneoPimClientBuilder::setHttpClient\(\) expects Akeneo\\Pim\\ApiClient\\Client\\ClientInterface, Psr\\Http\\Client\\ClientInterface given\.#'
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function createProductApiAdapter(): ApiAdapterInterface
{
return new ProductApiAdapter(
$this->createAkeneoPimSdkFactory()->createAkeneoPimClient($this->config),
$this->wrapperFactory
$this->wrapperFactory,
);
}

Expand All @@ -68,7 +68,7 @@ public function createCategoryApiAdapter(): ApiAdapterInterface
{
return new CategoryApiAdapter(
$this->createAkeneoPimSdkFactory()->createAkeneoPimClient($this->config),
$this->wrapperFactory
$this->wrapperFactory,
);
}

Expand All @@ -79,7 +79,7 @@ public function createAttributeApiAdapter(): ApiAdapterInterface
{
return new AttributeApiAdapter(
$this->createAkeneoPimSdkFactory()->createAkeneoPimClient($this->config),
$this->wrapperFactory
$this->wrapperFactory,
);
}

Expand All @@ -90,7 +90,7 @@ public function createAttributeGroupApiAdapter(): ApiAdapterInterface
{
return new AttributeGroupApiAdapter(
$this->createAkeneoPimSdkFactory()->createAkeneoPimClient($this->config),
$this->wrapperFactory
$this->wrapperFactory,
);
}

Expand All @@ -101,7 +101,7 @@ public function createAttributeOptionApiAdapter(): AttributeOptionApiAdapterInte
{
return new AttributeOptionApiAdapter(
$this->createAkeneoPimSdkFactory()->createAkeneoPimClient($this->config),
$this->wrapperFactory
$this->wrapperFactory,
);
}

Expand All @@ -112,7 +112,7 @@ public function createAssociationTypeApiAdapter(): ApiAdapterInterface
{
return new AssociationTypeApiAdapter(
$this->createAkeneoPimSdkFactory()->createAkeneoPimClient($this->config),
$this->wrapperFactory
$this->wrapperFactory,
);
}

Expand All @@ -123,7 +123,7 @@ public function createChannelApiAdapter(): ApiAdapterInterface
{
return new ChannelApiAdapter(
$this->createAkeneoPimSdkFactory()->createAkeneoPimClient($this->config),
$this->wrapperFactory
$this->wrapperFactory,
);
}

Expand All @@ -134,7 +134,7 @@ public function createCurrencyApiAdapter(): ApiAdapterInterface
{
return new CurrencyApiAdapter(
$this->createAkeneoPimSdkFactory()->createAkeneoPimClient($this->config),
$this->wrapperFactory
$this->wrapperFactory,
);
}

Expand All @@ -145,7 +145,7 @@ public function createFamilyApiAdapter(): ApiAdapterInterface
{
return new FamilyApiAdapter(
$this->createAkeneoPimSdkFactory()->createAkeneoPimClient($this->config),
$this->wrapperFactory
$this->wrapperFactory,
);
}

Expand All @@ -156,7 +156,7 @@ public function createFamilyVariantApiAdapter(): FamilyVariantApiAdapterInterfac
{
return new FamilyVariantApiAdapter(
$this->createAkeneoPimSdkFactory()->createAkeneoPimClient($this->config),
$this->wrapperFactory
$this->wrapperFactory,
);
}

Expand All @@ -167,7 +167,7 @@ public function createLocaleApiAdapter(): ApiAdapterInterface
{
return new LocaleApiAdapter(
$this->createAkeneoPimSdkFactory()->createAkeneoPimClient($this->config),
$this->wrapperFactory
$this->wrapperFactory,
);
}

Expand All @@ -178,7 +178,7 @@ public function createMeasureFamilyApiAdapter(): ApiAdapterInterface
{
return new MeasureFamilyApiAdapter(
$this->createAkeneoPimSdkFactory()->createAkeneoPimClient($this->config),
$this->wrapperFactory
$this->wrapperFactory,
);
}

Expand All @@ -189,7 +189,7 @@ public function createProductMediaFileApiAdapter(): ApiAdapterInterface
{
return new ProductMediaFileApiAdapter(
$this->createAkeneoPimSdkFactory()->createAkeneoPimClient($this->config),
$this->wrapperFactory
$this->wrapperFactory,
);
}

Expand All @@ -200,7 +200,7 @@ public function createProductModelApiAdapter(): ApiAdapterInterface
{
return new ProductModelApiAdapter(
$this->createAkeneoPimSdkFactory()->createAkeneoPimClient($this->config),
$this->wrapperFactory
$this->wrapperFactory,
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Adapter\HttpClient;

use GuzzleHttp\Client as GuzzleHttpClient;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\Utils;
use Http\Promise\Promise as HttpPromise;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use function GuzzleHttp\choose_handler;

abstract class AbstractHttpClient
{
/**
* @var \GuzzleHttp\ClientInterface
*/
protected $client;

public function __construct()
{
$this->client = $this->buildClient();
}

/**
* @param \Psr\Http\Message\RequestInterface $request
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function sendRequest(RequestInterface $request): ResponseInterface
{
return $this->client->send($request);
}

/**
* @param \Psr\Http\Message\RequestInterface $request
*
* @return \Http\Promise\Promise
*/
public function sendAsyncRequest(RequestInterface $request): HttpPromise
{
$promise = $this->client->sendAsync($request);

return new Promise($promise, $request);
}

/**
* @return \GuzzleHttp\ClientInterface
*/
protected function buildClient(): ClientInterface
{
$handlerStack = $this->createHandlerStack();
$handlerStack->push(Middleware::prepareBody(), 'prepare_body');

return new GuzzleHttpClient(['handler' => $handlerStack]);
}

/**
* @return \GuzzleHttp\HandlerStack
*/
protected function createHandlerStack(): HandlerStack
{
if (method_exists(Utils::class, 'chooseHandler')) {
return new HandlerStack(Utils::chooseHandler());
}

return new HandlerStack(choose_handler());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Adapter\HttpClient;

use Akeneo\Pim\ApiClient\Client\ClientInterface;

class AkeneoHttpClient extends AbstractHttpClient implements ClientInterface
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,71 +7,8 @@

namespace SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Adapter\HttpClient;

use GuzzleHttp\Client as GuzzleHttpClient;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\Utils;
use Http\Client\HttpClient;
use Http\Promise\Promise as HttpPromise;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use function GuzzleHttp\choose_handler;
use Psr\Http\Client\ClientInterface;

class Client implements HttpClient
class Client extends AbstractHttpClient implements ClientInterface
{
/**
* @var \GuzzleHttp\ClientInterface
*/
protected $client;

public function __construct()
{
$this->client = $this->buildClient();
}

/**
* @param \Psr\Http\Message\RequestInterface $request
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function sendRequest(RequestInterface $request): ResponseInterface
{
return $this->sendAsyncRequest($request)->wait();
}

/**
* @param \Psr\Http\Message\RequestInterface $request
*
* @return \Http\Promise\Promise
*/
protected function sendAsyncRequest(RequestInterface $request): HttpPromise
{
$promise = $this->client->sendAsync($request);

return new Promise($promise, $request);
}

/**
* @return \GuzzleHttp\ClientInterface
*/
protected function buildClient(): ClientInterface
{
$handlerStack = $this->createHandlerStack();
$handlerStack->push(Middleware::prepareBody(), 'prepare_body');

return new GuzzleHttpClient(['handler' => $handlerStack]);
}

/**
* @return \GuzzleHttp\HandlerStack
*/
protected function createHandlerStack(): HandlerStack
{
if (method_exists(Utils::class, 'chooseHandler')) {
return new HandlerStack(Utils::chooseHandler());
}

return new HandlerStack(choose_handler());
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Adapter\HttpClient\Exception;

use Http\Client\Exception;
use UnexpectedValueException as UnexpectedValueExceptionUnexpectedValueException;
abitskil marked this conversation as resolved.
Show resolved Hide resolved

class UnexpectedValueException extends \UnexpectedValueException implements Exception
class UnexpectedValueException extends UnexpectedValueExceptionUnexpectedValueException implements Exception
{
}
Loading
Loading