From 48cf2b484fbdff5256cef257d7d2ab44cf75b491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Planchat?= Date: Tue, 26 Oct 2021 23:33:39 +0200 Subject: [PATCH] Refactored the API endpoints and client --- composer.json | 8 +- .../{ => Legacy}/AuthenticationApiSpec.php | 6 +- spec/Client/AuthenticatedHttpClientSpec.php | 2 +- .../LegacyAuthenticatedHttpClientSpec.php | 159 +++++++++++ spec/Routing/UriGeneratorSpec.php | 2 +- ...entSpec.php => SyliusLegacyClientSpec.php} | 12 +- src/Api/Admin/AddressApi.php | 19 ++ src/Api/Admin/AddressApiInterface.php | 9 + src/Api/Admin/AdjustmentApi.php | 52 ++++ src/Api/Admin/AdjustmentApiInterface.php | 10 + src/Api/Admin/AdministratorApi.php | 67 +++++ src/Api/Admin/AdministratorApiInterface.php | 13 + src/Api/Admin/AvatarImageApi.php | 31 ++ src/Api/Admin/AvatarImageApiInterface.php | 11 + src/Api/Admin/CatalogPromotionApi.php | 61 ++++ .../Admin/CatalogPromotionApiInterface.php | 12 + .../Admin/CatalogPromotionTranslationApi.php | 19 ++ ...atalogPromotionTranslationApiInterface.php | 9 + src/Api/Admin/ChannelApi.php | 61 ++++ src/Api/Admin/ChannelApiInterface.php | 12 + src/Api/Admin/CountryApi.php | 61 ++++ src/Api/Admin/CountryApiInterface.php | 12 + src/Api/Admin/ProvinceApi.php | 58 ++++ src/Api/Admin/ProvinceApiInterface.php | 11 + src/Api/Admin/ShopBillingDataApi.php | 52 ++++ src/Api/Admin/ShopBillingDataApiInterface.php | 10 + src/Api/ApiAwareInterface.php | 8 +- src/Api/ApiAwareTrait.php | 23 +- src/Api/Legacy/AuthenticationApi.php | 81 ++++++ src/Api/Legacy/AuthenticationApiInterface.php | 32 +++ src/Api/{ => Legacy}/CartsApi.php | 3 +- src/Api/{ => Legacy}/CartsApiInterface.php | 3 +- src/Api/{ => Legacy}/ChannelsApi.php | 3 +- src/Api/{ => Legacy}/ChannelsApiInterface.php | 3 +- src/Api/{ => Legacy}/CountriesApi.php | 3 +- .../{ => Legacy}/CountriesApiInterface.php | 3 +- src/Api/{ => Legacy}/CurrenciesApi.php | 3 +- .../{ => Legacy}/CurrenciesApiInterface.php | 3 +- src/Api/{ => Legacy}/CustomersApi.php | 3 +- .../{ => Legacy}/CustomersApiInterface.php | 3 +- src/Api/{ => Legacy}/ExchangeRatesApi.php | 3 +- .../ExchangeRatesApiInterface.php | 3 +- src/Api/{ => Legacy}/LocalesApi.php | 3 +- src/Api/{ => Legacy}/LocalesApiInterface.php | 3 +- src/Api/{ => Legacy}/OrdersApi.php | 3 +- src/Api/{ => Legacy}/OrdersApiInterface.php | 3 +- src/Api/{ => Legacy}/PaymentMethodsApi.php | 3 +- .../PaymentMethodsApiInterface.php | 3 +- src/Api/{ => Legacy}/PaymentsApi.php | 3 +- src/Api/{ => Legacy}/PaymentsApiInterface.php | 3 +- .../ProductAssociationTypesApi.php | 3 +- .../ProductAssociationTypesApiInterface.php | 3 +- src/Api/{ => Legacy}/ProductAttributesApi.php | 3 +- .../ProductAttributesApiInterface.php | 3 +- src/Api/{ => Legacy}/ProductOptionsApi.php | 3 +- .../ProductOptionsApiInterface.php | 3 +- src/Api/{ => Legacy}/ProductReviewsApi.php | 3 +- .../ProductReviewsApiInterface.php | 3 +- src/Api/{ => Legacy}/ProductVariantsApi.php | 3 +- .../ProductVariantsApiInterface.php | 3 +- src/Api/{ => Legacy}/ProductsApi.php | 4 +- src/Api/{ => Legacy}/ProductsApiInterface.php | 3 +- src/Api/{ => Legacy}/PromotionCouponsApi.php | 3 +- .../PromotionCouponsApiInterface.php | 3 +- src/Api/{ => Legacy}/PromotionsApi.php | 3 +- .../{ => Legacy}/PromotionsApiInterface.php | 3 +- src/Api/{ => Legacy}/ShipmentsApi.php | 3 +- .../{ => Legacy}/ShipmentsApiInterface.php | 3 +- .../{ => Legacy}/ShippingCategoriesApi.php | 3 +- .../ShippingCategoriesApiInterface.php | 3 +- src/Api/{ => Legacy}/TaxCategoriesApi.php | 3 +- .../TaxCategoriesApiInterface.php | 3 +- src/Api/{ => Legacy}/TaxRatesApi.php | 3 +- src/Api/{ => Legacy}/TaxRatesApiInterface.php | 3 +- src/Api/{ => Legacy}/TaxonsApi.php | 3 +- src/Api/{ => Legacy}/TaxonsApiInterface.php | 3 +- src/Api/{ => Legacy}/UsersApi.php | 3 +- src/Api/{ => Legacy}/UsersApiInterface.php | 3 +- src/Api/{ => Legacy}/ZonesApi.php | 3 +- src/Api/{ => Legacy}/ZonesApiInterface.php | 3 +- .../Operation/CreatableResourceInterface.php | 6 +- .../DeletableDoubleResourceInterface.php | 6 +- .../Operation/DeletableResourceInterface.php | 4 +- .../DownloadableResourceInterface.php | 4 +- .../GettableDoubleResourceInterface.php | 8 +- .../Operation/GettableResourceInterface.php | 6 +- .../ListableDoubleResourceInterface.php | 22 +- .../Operation/ListableResourceInterface.php | 8 +- .../Operation/UpsertableResourceInterface.php | 4 +- .../UpsertableResourceListInterface.php | 2 +- src/Api/Shop/AddressApi.php | 67 +++++ src/Api/Shop/AddressApiInterface.php | 13 + src/Api/Shop/AdjustmentApi.php | 52 ++++ src/Api/Shop/AdjustmentApiInterface.php | 10 + src/Api/Shop/ChannelApi.php | 19 ++ src/Api/Shop/ChannelApiInterface.php | 9 + src/Api/Shop/CountryApi.php | 49 ++++ src/Api/Shop/CountryApiInterface.php | 10 + src/Client/LegacyAuthenticatedHttpClient.php | 84 ++++++ src/ClientBuilderInterface.php | 21 ++ src/Security/LegacyAuthentication.php | 100 +++++++ src/SyliusAdminClient.php | 73 +++++ src/SyliusAdminClientBuilderInterface.php | 15 + src/SyliusAdminClientDecorator.php | 85 ++++++ src/SyliusAdminClientInterface.php | 19 ++ src/SyliusClient.php | 265 +----------------- src/SyliusClientBuilder.php | 262 +---------------- src/SyliusClientBuilderInterface.php | 45 +-- src/SyliusClientInterface.php | 94 +------ src/SyliusLegacyClient.php | 182 ++++++++++++ src/SyliusLegacyClientBuilderInterface.php | 27 ++ ...or.php => SyliusLegacyClientDecorator.php} | 6 +- src/SyliusLegacyClientInterface.php | 68 +++++ src/SyliusShopClient.php | 38 +++ src/SyliusShopClientBuilderInterface.php | 15 + src/SyliusShopClientDecorator.php | 55 ++++ src/SyliusShopClientInterface.php | 13 + src/SyliusSyliusAdminClientBuilder.php | 189 +++++++++++++ src/SyliusSyliusLegacyClientFactory.php | 249 ++++++++++++++++ src/SyliusSyliusShopClientBuilder.php | 183 ++++++++++++ 120 files changed, 2698 insertions(+), 763 deletions(-) rename spec/Api/{ => Legacy}/AuthenticationApiSpec.php (94%) create mode 100644 spec/Client/LegacyAuthenticatedHttpClientSpec.php rename spec/{SyliusClientSpec.php => SyliusLegacyClientSpec.php} (95%) create mode 100644 src/Api/Admin/AddressApi.php create mode 100644 src/Api/Admin/AddressApiInterface.php create mode 100644 src/Api/Admin/AdjustmentApi.php create mode 100644 src/Api/Admin/AdjustmentApiInterface.php create mode 100644 src/Api/Admin/AdministratorApi.php create mode 100644 src/Api/Admin/AdministratorApiInterface.php create mode 100644 src/Api/Admin/AvatarImageApi.php create mode 100644 src/Api/Admin/AvatarImageApiInterface.php create mode 100644 src/Api/Admin/CatalogPromotionApi.php create mode 100644 src/Api/Admin/CatalogPromotionApiInterface.php create mode 100644 src/Api/Admin/CatalogPromotionTranslationApi.php create mode 100644 src/Api/Admin/CatalogPromotionTranslationApiInterface.php create mode 100644 src/Api/Admin/ChannelApi.php create mode 100644 src/Api/Admin/ChannelApiInterface.php create mode 100644 src/Api/Admin/CountryApi.php create mode 100644 src/Api/Admin/CountryApiInterface.php create mode 100644 src/Api/Admin/ProvinceApi.php create mode 100644 src/Api/Admin/ProvinceApiInterface.php create mode 100644 src/Api/Admin/ShopBillingDataApi.php create mode 100644 src/Api/Admin/ShopBillingDataApiInterface.php create mode 100644 src/Api/Legacy/AuthenticationApi.php create mode 100644 src/Api/Legacy/AuthenticationApiInterface.php rename src/Api/{ => Legacy}/CartsApi.php (96%) rename src/Api/{ => Legacy}/CartsApiInterface.php (86%) rename src/Api/{ => Legacy}/ChannelsApi.php (96%) rename src/Api/{ => Legacy}/ChannelsApiInterface.php (86%) rename src/Api/{ => Legacy}/CountriesApi.php (96%) rename src/Api/{ => Legacy}/CountriesApiInterface.php (86%) rename src/Api/{ => Legacy}/CurrenciesApi.php (96%) rename src/Api/{ => Legacy}/CurrenciesApiInterface.php (86%) rename src/Api/{ => Legacy}/CustomersApi.php (96%) rename src/Api/{ => Legacy}/CustomersApiInterface.php (86%) rename src/Api/{ => Legacy}/ExchangeRatesApi.php (96%) rename src/Api/{ => Legacy}/ExchangeRatesApiInterface.php (87%) rename src/Api/{ => Legacy}/LocalesApi.php (96%) rename src/Api/{ => Legacy}/LocalesApiInterface.php (86%) rename src/Api/{ => Legacy}/OrdersApi.php (96%) rename src/Api/{ => Legacy}/OrdersApiInterface.php (86%) rename src/Api/{ => Legacy}/PaymentMethodsApi.php (95%) rename src/Api/{ => Legacy}/PaymentMethodsApiInterface.php (82%) rename src/Api/{ => Legacy}/PaymentsApi.php (95%) rename src/Api/{ => Legacy}/PaymentsApiInterface.php (82%) rename src/Api/{ => Legacy}/ProductAssociationTypesApi.php (96%) rename src/Api/{ => Legacy}/ProductAssociationTypesApiInterface.php (87%) rename src/Api/{ => Legacy}/ProductAttributesApi.php (96%) rename src/Api/{ => Legacy}/ProductAttributesApiInterface.php (87%) rename src/Api/{ => Legacy}/ProductOptionsApi.php (96%) rename src/Api/{ => Legacy}/ProductOptionsApiInterface.php (87%) rename src/Api/{ => Legacy}/ProductReviewsApi.php (96%) rename src/Api/{ => Legacy}/ProductReviewsApiInterface.php (87%) rename src/Api/{ => Legacy}/ProductVariantsApi.php (96%) rename src/Api/{ => Legacy}/ProductVariantsApiInterface.php (87%) rename src/Api/{ => Legacy}/ProductsApi.php (96%) rename src/Api/{ => Legacy}/ProductsApiInterface.php (88%) rename src/Api/{ => Legacy}/PromotionCouponsApi.php (96%) rename src/Api/{ => Legacy}/PromotionCouponsApiInterface.php (87%) rename src/Api/{ => Legacy}/PromotionsApi.php (96%) rename src/Api/{ => Legacy}/PromotionsApiInterface.php (86%) rename src/Api/{ => Legacy}/ShipmentsApi.php (96%) rename src/Api/{ => Legacy}/ShipmentsApiInterface.php (86%) rename src/Api/{ => Legacy}/ShippingCategoriesApi.php (95%) rename src/Api/{ => Legacy}/ShippingCategoriesApiInterface.php (82%) rename src/Api/{ => Legacy}/TaxCategoriesApi.php (96%) rename src/Api/{ => Legacy}/TaxCategoriesApiInterface.php (87%) rename src/Api/{ => Legacy}/TaxRatesApi.php (95%) rename src/Api/{ => Legacy}/TaxRatesApiInterface.php (82%) rename src/Api/{ => Legacy}/TaxonsApi.php (96%) rename src/Api/{ => Legacy}/TaxonsApiInterface.php (86%) rename src/Api/{ => Legacy}/UsersApi.php (96%) rename src/Api/{ => Legacy}/UsersApiInterface.php (86%) rename src/Api/{ => Legacy}/ZonesApi.php (96%) rename src/Api/{ => Legacy}/ZonesApiInterface.php (86%) create mode 100644 src/Api/Shop/AddressApi.php create mode 100644 src/Api/Shop/AddressApiInterface.php create mode 100644 src/Api/Shop/AdjustmentApi.php create mode 100644 src/Api/Shop/AdjustmentApiInterface.php create mode 100644 src/Api/Shop/ChannelApi.php create mode 100644 src/Api/Shop/ChannelApiInterface.php create mode 100644 src/Api/Shop/CountryApi.php create mode 100644 src/Api/Shop/CountryApiInterface.php create mode 100644 src/Client/LegacyAuthenticatedHttpClient.php create mode 100644 src/ClientBuilderInterface.php create mode 100644 src/Security/LegacyAuthentication.php create mode 100644 src/SyliusAdminClient.php create mode 100644 src/SyliusAdminClientBuilderInterface.php create mode 100644 src/SyliusAdminClientDecorator.php create mode 100644 src/SyliusAdminClientInterface.php create mode 100644 src/SyliusLegacyClient.php create mode 100644 src/SyliusLegacyClientBuilderInterface.php rename src/{SyliusClientDecorator.php => SyliusLegacyClientDecorator.php} (97%) create mode 100644 src/SyliusLegacyClientInterface.php create mode 100644 src/SyliusShopClient.php create mode 100644 src/SyliusShopClientBuilderInterface.php create mode 100644 src/SyliusShopClientDecorator.php create mode 100644 src/SyliusShopClientInterface.php create mode 100644 src/SyliusSyliusAdminClientBuilder.php create mode 100644 src/SyliusSyliusLegacyClientFactory.php create mode 100644 src/SyliusSyliusShopClientBuilder.php diff --git a/composer.json b/composer.json index cc72ce5..d2bbfb8 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,7 @@ }, "autoload-dev": { "psr-4": { + "spec\\Diglin\\Sylius\\ApiClient\\": "spec/", "Diglin\\Sylius\\ApiClient\\tests\\": "tests/" } }, @@ -33,12 +34,13 @@ "php-http/message-factory": "^v1.0", "php-http/multipart-stream-builder": "^1.0", "php-http/client-implementation": "^1.0", - "symfony/expression-language": "^3.0|^4.0|^5.0" + "symfony/expression-language": "^3.0|^4.0|^5.0", + "webmozart/assert": "^1.10" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.14", - "phpunit/phpunit": "^5.7", - "phpspec/phpspec": "^5.0", + "phpunit/phpunit": "^9.0", + "phpspec/phpspec": "^7.1", "symfony/yaml": "^4.2", "donatj/mock-webserver": "^2.0", "php-http/guzzle6-adapter": "^2.0" diff --git a/spec/Api/AuthenticationApiSpec.php b/spec/Api/Legacy/AuthenticationApiSpec.php similarity index 94% rename from spec/Api/AuthenticationApiSpec.php rename to spec/Api/Legacy/AuthenticationApiSpec.php index d23b080..5a73d91 100644 --- a/spec/Api/AuthenticationApiSpec.php +++ b/spec/Api/Legacy/AuthenticationApiSpec.php @@ -1,9 +1,9 @@ beConstructedWith($httpClient, $authenticationApi, $authentication); + } + + public function it_is_initializable() + { + $this->shouldHaveType(LegacyAuthenticatedHttpClient::class); + $this->shouldImplement(HttpClientInterface::class); + } + + public function it_sends_an_authenticated_and_successful_request_when_access_token_is_defined( + $httpClient, + $authentication, + ResponseInterface $response + ) { + $authentication->getAccessToken()->willReturn('bar'); + + $httpClient->sendRequest( + 'POST', + 'http://diglin.com/api/rest/v1/products/foo', + ['Content-Type' => 'application/json', 'Authorization' => 'Bearer bar'], + '{"identifier": "foo"}' + )->willReturn($response); + + $this->sendRequest( + 'POST', + 'http://diglin.com/api/rest/v1/products/foo', + ['Content-Type' => 'application/json'], + '{"identifier": "foo"}' + )->shouldReturn($response); + } + + public function it_sends_an_authenticated_and_successful_request_at_first_call( + $httpClient, + $authenticationApi, + $authentication, + ResponseInterface $response + ) { + $authentication->getClientId()->willReturn('client_id'); + $authentication->getSecret()->willReturn('secret'); + $authentication->getUsername()->willReturn('julia'); + $authentication->getPassword()->willReturn('julia_pwd'); + $authentication->getAccessToken()->willReturn(null, 'foo'); + + $authenticationApi + ->authenticateByPassword('client_id', 'secret', 'julia', 'julia_pwd') + ->willReturn([ + 'access_token' => 'foo', + 'expires_in' => 3600, + 'token_type' => 'bearer', + 'scope' => null, + 'refresh_token' => 'bar', + ]) + ; + + $authentication + ->setAccessToken('foo') + ->shouldBeCalled() + ->willReturn($authentication) + ; + + $authentication + ->setRefreshToken('bar') + ->shouldBeCalled() + ->willReturn($authentication) + ; + + $httpClient->sendRequest( + 'POST', + 'http://diglin.com/api/rest/v1/products/foo', + ['Content-Type' => 'application/json', 'Authorization' => 'Bearer foo'], + '{"identifier": "foo"}' + )->willReturn($response); + + $this->sendRequest( + 'POST', + 'http://diglin.com/api/rest/v1/products/foo', + ['Content-Type' => 'application/json'], + '{"identifier": "foo"}' + )->shouldReturn($response); + } + + public function it_sends_an_authenticated_and_successful_request_when_access_token_expired( + $httpClient, + $authenticationApi, + $authentication, + ResponseInterface $response + ) { + $authentication->getClientId()->willReturn('client_id'); + $authentication->getSecret()->willReturn('secret'); + $authentication->getUsername()->willReturn('julia'); + $authentication->getPassword()->willReturn('julia_pwd'); + $authentication->getAccessToken()->willReturn('foo', 'foo', 'baz'); + $authentication->getRefreshToken()->willReturn('bar'); + + $httpClient->sendRequest( + 'POST', + 'http://diglin.com/api/rest/v1/products/foo', + ['Content-Type' => 'application/json', 'Authorization' => 'Bearer foo'], + '{"identifier": "foo"}' + )->willThrow(UnauthorizedHttpException::class); + + $authenticationApi + ->authenticateByRefreshToken('client_id', 'secret', 'bar') + ->willReturn([ + 'access_token' => 'baz', + 'expires_in' => 3600, + 'token_type' => 'bearer', + 'scope' => null, + 'refresh_token' => 'foz', + ]) + ; + + $authentication + ->setAccessToken('baz') + ->shouldBeCalled() + ->willReturn($authentication) + ; + + $authentication + ->setRefreshToken('foz') + ->shouldBeCalled() + ->willReturn($authentication) + ; + + $httpClient->sendRequest( + 'POST', + 'http://diglin.com/api/rest/v1/products/foo', + ['Content-Type' => 'application/json', 'Authorization' => 'Bearer baz'], + '{"identifier": "foo"}' + )->willReturn($response); + + $this->sendRequest( + 'POST', + 'http://diglin.com/api/rest/v1/products/foo', + ['Content-Type' => 'application/json'], + '{"identifier": "foo"}' + ); + } +} diff --git a/spec/Routing/UriGeneratorSpec.php b/spec/Routing/UriGeneratorSpec.php index 2a6a5d7..c87ba4a 100644 --- a/spec/Routing/UriGeneratorSpec.php +++ b/spec/Routing/UriGeneratorSpec.php @@ -85,7 +85,7 @@ public function it_generates_uri_having_search_parameter_encoded_in_json() $this ->generate('/api', [], $queryParameters) - ->shouldReturn(static::BASE_URI.'api?search=%7B%22categories%22%3A%5B%7B%22operator%22%3A%22IN%22%2C%22value%22%3A%22master%22%7D%5D%7D') + ->shouldReturn(static::BASE_URI.'api?search%5Bcategories%5D%5B0%5D%5Boperator%5D=IN&search%5Bcategories%5D%5B0%5D%5Bvalue%5D=master') ; } } diff --git a/spec/SyliusClientSpec.php b/spec/SyliusLegacyClientSpec.php similarity index 95% rename from spec/SyliusClientSpec.php rename to spec/SyliusLegacyClientSpec.php index d84d5f6..d2f1f23 100644 --- a/spec/SyliusClientSpec.php +++ b/spec/SyliusLegacyClientSpec.php @@ -2,13 +2,13 @@ namespace spec\Diglin\Sylius\ApiClient; -use Diglin\Sylius\ApiClient\Api; +use Diglin\Sylius\ApiClient\Api\Legacy as Api; use Diglin\Sylius\ApiClient\Security\Authentication; -use Diglin\Sylius\ApiClient\SyliusClient; -use Diglin\Sylius\ApiClient\SyliusClientInterface; +use Diglin\Sylius\ApiClient\SyliusAdminClient; +use Diglin\Sylius\ApiClient\SyliusAdminClientInterface; use PhpSpec\ObjectBehavior; -class SyliusClientSpec extends ObjectBehavior +class SyliusLegacyClientSpec extends ObjectBehavior { public function let( Authentication $authentication, @@ -70,8 +70,8 @@ public function let( public function it_is_initializable() { - $this->shouldImplement(SyliusClientInterface::class); - $this->shouldHaveType(SyliusClient::class); + $this->shouldImplement(SyliusAdminClientInterface::class); + $this->shouldHaveType(SyliusAdminClient::class); } public function it_gets_access_token($authentication) diff --git a/src/Api/Admin/AddressApi.php b/src/Api/Admin/AddressApi.php new file mode 100644 index 0000000..1602d17 --- /dev/null +++ b/src/Api/Admin/AddressApi.php @@ -0,0 +1,19 @@ +resourceClient->getResource('api/v2/admin/addresses/%d', [$code]); + } +} diff --git a/src/Api/Admin/AddressApiInterface.php b/src/Api/Admin/AddressApiInterface.php new file mode 100644 index 0000000..e190803 --- /dev/null +++ b/src/Api/Admin/AddressApiInterface.php @@ -0,0 +1,9 @@ +resourceClient->getResource('api/v2/admin/adjustments/%d', [$code]); + } + + public function listPerPage( + $code, + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + Assert::string($code); + $data = $this->resourceClient->getResources('api/v2/admin/order-items/%s/adjustments', [$code]); + + return $this->pageFactory->createPage($data); + } + + public function all( + $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } +} diff --git a/src/Api/Admin/AdjustmentApiInterface.php b/src/Api/Admin/AdjustmentApiInterface.php new file mode 100644 index 0000000..cb04e34 --- /dev/null +++ b/src/Api/Admin/AdjustmentApiInterface.php @@ -0,0 +1,10 @@ +resourceClient->getResource('api/v2/admin/administrators/%d', [$code]); + } + + public function create($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->createResource('api/v2/admin/administrators', [], $data); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/administrators'); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function upsert($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->upsertResource('api/v2/admin/administrators/%d', [$code], $data); + } + + public function delete($code): int + { + Assert::integer($code); + return $this->resourceClient->deleteResource('api/v2/admin/administrators/%d', [$code]); + } +} diff --git a/src/Api/Admin/AdministratorApiInterface.php b/src/Api/Admin/AdministratorApiInterface.php new file mode 100644 index 0000000..0ef12ce --- /dev/null +++ b/src/Api/Admin/AdministratorApiInterface.php @@ -0,0 +1,13 @@ +resourceClient->getResource('api/v2/admin/avatar-images/%d', [$code]); + } + + public function create($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->createResource('api/v2/admin/avatar-images', [], $data); + } + + public function delete($code): int + { + Assert::integer($code); + return $this->resourceClient->deleteResource('api/v2/admin/avatar-images/%d', [$code]); + } +} diff --git a/src/Api/Admin/AvatarImageApiInterface.php b/src/Api/Admin/AvatarImageApiInterface.php new file mode 100644 index 0000000..36d3e8b --- /dev/null +++ b/src/Api/Admin/AvatarImageApiInterface.php @@ -0,0 +1,11 @@ +resourceClient->getResource('api/v2/admin/catalog-promotions/%d', [$code]); + } + + public function create($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->createResource('api/v2/admin/catalog-promotions', [], $data); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/catalog-promotions'); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function upsert($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->upsertResource('api/v2/admin/catalog-promotions/%d', [$code], $data); + } +} diff --git a/src/Api/Admin/CatalogPromotionApiInterface.php b/src/Api/Admin/CatalogPromotionApiInterface.php new file mode 100644 index 0000000..57ee805 --- /dev/null +++ b/src/Api/Admin/CatalogPromotionApiInterface.php @@ -0,0 +1,12 @@ +resourceClient->getResource('api/v2/admin/catalog-promotion-translations/%d', [$code]); + } +} diff --git a/src/Api/Admin/CatalogPromotionTranslationApiInterface.php b/src/Api/Admin/CatalogPromotionTranslationApiInterface.php new file mode 100644 index 0000000..2c06e32 --- /dev/null +++ b/src/Api/Admin/CatalogPromotionTranslationApiInterface.php @@ -0,0 +1,9 @@ +resourceClient->getResource('api/v2/admin/channels/%d', [$code]); + } + + public function create($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->createResource('api/v2/admin/channels', [], $data); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/channels'); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function delete($code): int + { + Assert::string($code); + return $this->resourceClient->deleteResource('api/v2/admin/channels/%d', [$code]); + } +} diff --git a/src/Api/Admin/ChannelApiInterface.php b/src/Api/Admin/ChannelApiInterface.php new file mode 100644 index 0000000..3d75a81 --- /dev/null +++ b/src/Api/Admin/ChannelApiInterface.php @@ -0,0 +1,12 @@ +resourceClient->getResource('api/v2/admin/countries/%s', [$code]); + } + + public function create($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->createResource('api/v2/admin/countries', [], $data); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/countries', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function delete($code): int + { + Assert::string($code); + return $this->resourceClient->deleteResource('api/v2/admin/countries/%s', [$code]); + } +} diff --git a/src/Api/Admin/CountryApiInterface.php b/src/Api/Admin/CountryApiInterface.php new file mode 100644 index 0000000..566b2b7 --- /dev/null +++ b/src/Api/Admin/CountryApiInterface.php @@ -0,0 +1,12 @@ +resourceClient->getResource('api/v2/admin/provinces/%s', [$code]); + } + + public function listPerPage( + $code, + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/countries/%d/provinces', [$code], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + Assert::string($code); + $data = $this->listPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function upsert($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->upsertResource('api/v2/admin/provinces/%d', [$code], $data); + } +} diff --git a/src/Api/Admin/ProvinceApiInterface.php b/src/Api/Admin/ProvinceApiInterface.php new file mode 100644 index 0000000..1c73cd1 --- /dev/null +++ b/src/Api/Admin/ProvinceApiInterface.php @@ -0,0 +1,11 @@ +resourceClient->getResource('api/v2/admin/shop-billing-datas/%d', [$code]); + } + + public function listPerPage( + $code, + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + Assert::string($code); + $data = $this->resourceClient->getResources('api/v2/admin/channels/%s/shop-billing-data', [$code]); + + return $this->pageFactory->createPage($data); + } + + public function all( + $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } +} diff --git a/src/Api/Admin/ShopBillingDataApiInterface.php b/src/Api/Admin/ShopBillingDataApiInterface.php new file mode 100644 index 0000000..62e2530 --- /dev/null +++ b/src/Api/Admin/ShopBillingDataApiInterface.php @@ -0,0 +1,10 @@ +resourceClient = $resourceClient; } - public function setPageFactory(PageFactoryInterface $pageFactory) + public function setPageFactory(PageFactoryInterface $pageFactory): void { $this->pageFactory = $pageFactory; } - public function setCursorFactory(ResourceCursorFactoryInterface $cursorFactory) + public function setCursorFactory(ResourceCursorFactoryInterface $cursorFactory): void { $this->cursorFactory = $cursorFactory; } - public function setFileSystem(FileSystemInterface $fileSystem) + public function setFileSystem(FileSystemInterface $fileSystem): void { $this->fileSystem = $fileSystem; } diff --git a/src/Api/Legacy/AuthenticationApi.php b/src/Api/Legacy/AuthenticationApi.php new file mode 100644 index 0000000..ebe3fbb --- /dev/null +++ b/src/Api/Legacy/AuthenticationApi.php @@ -0,0 +1,81 @@ + + * + * @category SyliusApiClient + * + * @copyright 2020 - Diglin (https://www.diglin.com) + */ + +namespace Diglin\Sylius\ApiClient\Api\Legacy; + +use Diglin\Sylius\ApiClient\Client\HttpClient; +use Diglin\Sylius\ApiClient\Routing\UriGeneratorInterface; + +/** + * API implementation to manage the authentication. + * + * @author Alexandre Hocquard + * @copyright 2017 Akeneo SAS (http://www.akeneo.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ +final class AuthenticationApi implements AuthenticationApiInterface +{ + public const TOKEN_URI = 'api/oauth/v2/token'; + + public function __construct( + private HttpClient $httpClient, + private UriGeneratorInterface $uriGenerator + ) {} + + /** + * {@inheritdoc} + */ + public function authenticateByPassword(string $clientId, string $secret, string $username, string $password): array + { + $requestBody = [ + 'grant_type' => 'password', + 'username' => $username, + 'password' => $password, + 'client_id' => $clientId, + 'client_secret' => $secret, + ]; + + return $this->authenticate($requestBody); + } + + /** + * {@inheritdoc} + */ + public function authenticateByRefreshToken(string $clientId, string $secret, string $refreshToken): array + { + $requestBody = [ + 'grant_type' => 'refresh_token', + 'refresh_token' => $refreshToken, + ]; + + return $this->authenticate($requestBody); + } + + /** + * Authenticates the client by requesting the access token and the refresh token. + * + * @param array $requestBody body of the request to authenticate + * + * @return array returns the body of the response containing access token and refresh token + */ + protected function authenticate(array $requestBody) + { + $headers = [ + 'Content-Type' => 'application/json', + ]; + + $uri = $this->uriGenerator->generate(static::TOKEN_URI); + + $response = $this->httpClient->sendRequest('POST', $uri, $headers, json_encode($requestBody)); + + return json_decode($response->getBody()->getContents(), true); + } +} diff --git a/src/Api/Legacy/AuthenticationApiInterface.php b/src/Api/Legacy/AuthenticationApiInterface.php new file mode 100644 index 0000000..a7a761b --- /dev/null +++ b/src/Api/Legacy/AuthenticationApiInterface.php @@ -0,0 +1,32 @@ + + * + * @category SyliusApiClient + * + * @copyright 2020 - Diglin (https://www.diglin.com) + */ + +namespace Diglin\Sylius\ApiClient\Api\Legacy; + +/** + * API to manage the authentication. + * + * @author Alexandre Hocquard + * @copyright 2017 Akeneo SAS (http://www.akeneo.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ +interface AuthenticationApiInterface +{ + /** + * Authenticates with the password grant type. + */ + public function authenticateByPassword(string $clientId, string $secret, string $username, string $password): array; + + /** + * Authenticates with the refresh token grant type. + */ + public function authenticateByRefreshToken(string $clientId, string $secret, string $refreshToken): array; +} diff --git a/src/Api/CartsApi.php b/src/Api/Legacy/CartsApi.php similarity index 96% rename from src/Api/CartsApi.php rename to src/Api/Legacy/CartsApi.php index 8260dd2..7506306 100644 --- a/src/Api/CartsApi.php +++ b/src/Api/Legacy/CartsApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/CartsApiInterface.php b/src/Api/Legacy/CartsApiInterface.php similarity index 86% rename from src/Api/CartsApiInterface.php rename to src/Api/Legacy/CartsApiInterface.php index a643fb0..fd8b62e 100644 --- a/src/Api/CartsApiInterface.php +++ b/src/Api/Legacy/CartsApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; diff --git a/src/Api/ChannelsApi.php b/src/Api/Legacy/ChannelsApi.php similarity index 96% rename from src/Api/ChannelsApi.php rename to src/Api/Legacy/ChannelsApi.php index 65f3720..09f5970 100644 --- a/src/Api/ChannelsApi.php +++ b/src/Api/Legacy/ChannelsApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/ChannelsApiInterface.php b/src/Api/Legacy/ChannelsApiInterface.php similarity index 86% rename from src/Api/ChannelsApiInterface.php rename to src/Api/Legacy/ChannelsApiInterface.php index 34eab4c..6590a45 100644 --- a/src/Api/ChannelsApiInterface.php +++ b/src/Api/Legacy/ChannelsApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; diff --git a/src/Api/CountriesApi.php b/src/Api/Legacy/CountriesApi.php similarity index 96% rename from src/Api/CountriesApi.php rename to src/Api/Legacy/CountriesApi.php index 8be4428..9bb7fe6 100644 --- a/src/Api/CountriesApi.php +++ b/src/Api/Legacy/CountriesApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/CountriesApiInterface.php b/src/Api/Legacy/CountriesApiInterface.php similarity index 86% rename from src/Api/CountriesApiInterface.php rename to src/Api/Legacy/CountriesApiInterface.php index c01ec73..433fa4a 100644 --- a/src/Api/CountriesApiInterface.php +++ b/src/Api/Legacy/CountriesApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; diff --git a/src/Api/CurrenciesApi.php b/src/Api/Legacy/CurrenciesApi.php similarity index 96% rename from src/Api/CurrenciesApi.php rename to src/Api/Legacy/CurrenciesApi.php index f341338..3698040 100644 --- a/src/Api/CurrenciesApi.php +++ b/src/Api/Legacy/CurrenciesApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/CurrenciesApiInterface.php b/src/Api/Legacy/CurrenciesApiInterface.php similarity index 86% rename from src/Api/CurrenciesApiInterface.php rename to src/Api/Legacy/CurrenciesApiInterface.php index 1cc4328..9848136 100644 --- a/src/Api/CurrenciesApiInterface.php +++ b/src/Api/Legacy/CurrenciesApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; diff --git a/src/Api/CustomersApi.php b/src/Api/Legacy/CustomersApi.php similarity index 96% rename from src/Api/CustomersApi.php rename to src/Api/Legacy/CustomersApi.php index 2a4b842..36c2e77 100644 --- a/src/Api/CustomersApi.php +++ b/src/Api/Legacy/CustomersApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Exception\HttpException; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; diff --git a/src/Api/CustomersApiInterface.php b/src/Api/Legacy/CustomersApiInterface.php similarity index 86% rename from src/Api/CustomersApiInterface.php rename to src/Api/Legacy/CustomersApiInterface.php index 51c118d..55f3e42 100644 --- a/src/Api/CustomersApiInterface.php +++ b/src/Api/Legacy/CustomersApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; diff --git a/src/Api/ExchangeRatesApi.php b/src/Api/Legacy/ExchangeRatesApi.php similarity index 96% rename from src/Api/ExchangeRatesApi.php rename to src/Api/Legacy/ExchangeRatesApi.php index 3761eaa..e066eaa 100644 --- a/src/Api/ExchangeRatesApi.php +++ b/src/Api/Legacy/ExchangeRatesApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/ExchangeRatesApiInterface.php b/src/Api/Legacy/ExchangeRatesApiInterface.php similarity index 87% rename from src/Api/ExchangeRatesApiInterface.php rename to src/Api/Legacy/ExchangeRatesApiInterface.php index c6983de..daf9566 100644 --- a/src/Api/ExchangeRatesApiInterface.php +++ b/src/Api/Legacy/ExchangeRatesApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; diff --git a/src/Api/LocalesApi.php b/src/Api/Legacy/LocalesApi.php similarity index 96% rename from src/Api/LocalesApi.php rename to src/Api/Legacy/LocalesApi.php index 97c756d..ad773d4 100644 --- a/src/Api/LocalesApi.php +++ b/src/Api/Legacy/LocalesApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/LocalesApiInterface.php b/src/Api/Legacy/LocalesApiInterface.php similarity index 86% rename from src/Api/LocalesApiInterface.php rename to src/Api/Legacy/LocalesApiInterface.php index f5103c8..d2c472f 100644 --- a/src/Api/LocalesApiInterface.php +++ b/src/Api/Legacy/LocalesApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; diff --git a/src/Api/OrdersApi.php b/src/Api/Legacy/OrdersApi.php similarity index 96% rename from src/Api/OrdersApi.php rename to src/Api/Legacy/OrdersApi.php index fb9c5e1..40ebc80 100644 --- a/src/Api/OrdersApi.php +++ b/src/Api/Legacy/OrdersApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/OrdersApiInterface.php b/src/Api/Legacy/OrdersApiInterface.php similarity index 86% rename from src/Api/OrdersApiInterface.php rename to src/Api/Legacy/OrdersApiInterface.php index 512edbd..98fc3b1 100644 --- a/src/Api/OrdersApiInterface.php +++ b/src/Api/Legacy/OrdersApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; diff --git a/src/Api/PaymentMethodsApi.php b/src/Api/Legacy/PaymentMethodsApi.php similarity index 95% rename from src/Api/PaymentMethodsApi.php rename to src/Api/Legacy/PaymentMethodsApi.php index 1e73129..de3ec62 100644 --- a/src/Api/PaymentMethodsApi.php +++ b/src/Api/Legacy/PaymentMethodsApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/PaymentMethodsApiInterface.php b/src/Api/Legacy/PaymentMethodsApiInterface.php similarity index 82% rename from src/Api/PaymentMethodsApiInterface.php rename to src/Api/Legacy/PaymentMethodsApiInterface.php index d5daea2..4986e6f 100644 --- a/src/Api/PaymentMethodsApiInterface.php +++ b/src/Api/Legacy/PaymentMethodsApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; diff --git a/src/Api/PaymentsApi.php b/src/Api/Legacy/PaymentsApi.php similarity index 95% rename from src/Api/PaymentsApi.php rename to src/Api/Legacy/PaymentsApi.php index 4b68728..bbb6fe3 100644 --- a/src/Api/PaymentsApi.php +++ b/src/Api/Legacy/PaymentsApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/PaymentsApiInterface.php b/src/Api/Legacy/PaymentsApiInterface.php similarity index 82% rename from src/Api/PaymentsApiInterface.php rename to src/Api/Legacy/PaymentsApiInterface.php index 2ae4362..86548e4 100644 --- a/src/Api/PaymentsApiInterface.php +++ b/src/Api/Legacy/PaymentsApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; diff --git a/src/Api/ProductAssociationTypesApi.php b/src/Api/Legacy/ProductAssociationTypesApi.php similarity index 96% rename from src/Api/ProductAssociationTypesApi.php rename to src/Api/Legacy/ProductAssociationTypesApi.php index ee39d6c..7bd0527 100644 --- a/src/Api/ProductAssociationTypesApi.php +++ b/src/Api/Legacy/ProductAssociationTypesApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/ProductAssociationTypesApiInterface.php b/src/Api/Legacy/ProductAssociationTypesApiInterface.php similarity index 87% rename from src/Api/ProductAssociationTypesApiInterface.php rename to src/Api/Legacy/ProductAssociationTypesApiInterface.php index 5471ecc..49be513 100644 --- a/src/Api/ProductAssociationTypesApiInterface.php +++ b/src/Api/Legacy/ProductAssociationTypesApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; diff --git a/src/Api/ProductAttributesApi.php b/src/Api/Legacy/ProductAttributesApi.php similarity index 96% rename from src/Api/ProductAttributesApi.php rename to src/Api/Legacy/ProductAttributesApi.php index c7b3472..54a6fb3 100644 --- a/src/Api/ProductAttributesApi.php +++ b/src/Api/Legacy/ProductAttributesApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/ProductAttributesApiInterface.php b/src/Api/Legacy/ProductAttributesApiInterface.php similarity index 87% rename from src/Api/ProductAttributesApiInterface.php rename to src/Api/Legacy/ProductAttributesApiInterface.php index 4cb8ff2..31ec91e 100644 --- a/src/Api/ProductAttributesApiInterface.php +++ b/src/Api/Legacy/ProductAttributesApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; diff --git a/src/Api/ProductOptionsApi.php b/src/Api/Legacy/ProductOptionsApi.php similarity index 96% rename from src/Api/ProductOptionsApi.php rename to src/Api/Legacy/ProductOptionsApi.php index 7d5e351..dad931c 100644 --- a/src/Api/ProductOptionsApi.php +++ b/src/Api/Legacy/ProductOptionsApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/ProductOptionsApiInterface.php b/src/Api/Legacy/ProductOptionsApiInterface.php similarity index 87% rename from src/Api/ProductOptionsApiInterface.php rename to src/Api/Legacy/ProductOptionsApiInterface.php index ecda171..cee3094 100644 --- a/src/Api/ProductOptionsApiInterface.php +++ b/src/Api/Legacy/ProductOptionsApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; diff --git a/src/Api/ProductReviewsApi.php b/src/Api/Legacy/ProductReviewsApi.php similarity index 96% rename from src/Api/ProductReviewsApi.php rename to src/Api/Legacy/ProductReviewsApi.php index e959ca0..0aecb85 100644 --- a/src/Api/ProductReviewsApi.php +++ b/src/Api/Legacy/ProductReviewsApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/ProductReviewsApiInterface.php b/src/Api/Legacy/ProductReviewsApiInterface.php similarity index 87% rename from src/Api/ProductReviewsApiInterface.php rename to src/Api/Legacy/ProductReviewsApiInterface.php index d2c6466..9e25525 100644 --- a/src/Api/ProductReviewsApiInterface.php +++ b/src/Api/Legacy/ProductReviewsApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableDoubleResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableDoubleResourceInterface; diff --git a/src/Api/ProductVariantsApi.php b/src/Api/Legacy/ProductVariantsApi.php similarity index 96% rename from src/Api/ProductVariantsApi.php rename to src/Api/Legacy/ProductVariantsApi.php index 88cdfab..bb866f1 100644 --- a/src/Api/ProductVariantsApi.php +++ b/src/Api/Legacy/ProductVariantsApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/ProductVariantsApiInterface.php b/src/Api/Legacy/ProductVariantsApiInterface.php similarity index 87% rename from src/Api/ProductVariantsApiInterface.php rename to src/Api/Legacy/ProductVariantsApiInterface.php index 927e0ed..28639ca 100644 --- a/src/Api/ProductVariantsApiInterface.php +++ b/src/Api/Legacy/ProductVariantsApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableDoubleResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableDoubleResourceInterface; diff --git a/src/Api/ProductsApi.php b/src/Api/Legacy/ProductsApi.php similarity index 96% rename from src/Api/ProductsApi.php rename to src/Api/Legacy/ProductsApi.php index d1f111f..3e24caa 100644 --- a/src/Api/ProductsApi.php +++ b/src/Api/Legacy/ProductsApi.php @@ -9,10 +9,10 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; -use Diglin\Sylius\ApiClient\Exception\HttpException; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; diff --git a/src/Api/ProductsApiInterface.php b/src/Api/Legacy/ProductsApiInterface.php similarity index 88% rename from src/Api/ProductsApiInterface.php rename to src/Api/Legacy/ProductsApiInterface.php index e2f3c22..22e9e40 100644 --- a/src/Api/ProductsApiInterface.php +++ b/src/Api/Legacy/ProductsApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; diff --git a/src/Api/PromotionCouponsApi.php b/src/Api/Legacy/PromotionCouponsApi.php similarity index 96% rename from src/Api/PromotionCouponsApi.php rename to src/Api/Legacy/PromotionCouponsApi.php index 65bb341..dae426a 100644 --- a/src/Api/PromotionCouponsApi.php +++ b/src/Api/Legacy/PromotionCouponsApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/PromotionCouponsApiInterface.php b/src/Api/Legacy/PromotionCouponsApiInterface.php similarity index 87% rename from src/Api/PromotionCouponsApiInterface.php rename to src/Api/Legacy/PromotionCouponsApiInterface.php index 78cac06..d384066 100644 --- a/src/Api/PromotionCouponsApiInterface.php +++ b/src/Api/Legacy/PromotionCouponsApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableDoubleResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableDoubleResourceInterface; diff --git a/src/Api/PromotionsApi.php b/src/Api/Legacy/PromotionsApi.php similarity index 96% rename from src/Api/PromotionsApi.php rename to src/Api/Legacy/PromotionsApi.php index ed1e895..1ae05cb 100644 --- a/src/Api/PromotionsApi.php +++ b/src/Api/Legacy/PromotionsApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/PromotionsApiInterface.php b/src/Api/Legacy/PromotionsApiInterface.php similarity index 86% rename from src/Api/PromotionsApiInterface.php rename to src/Api/Legacy/PromotionsApiInterface.php index 9c4e8d3..4d09564 100644 --- a/src/Api/PromotionsApiInterface.php +++ b/src/Api/Legacy/PromotionsApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; diff --git a/src/Api/ShipmentsApi.php b/src/Api/Legacy/ShipmentsApi.php similarity index 96% rename from src/Api/ShipmentsApi.php rename to src/Api/Legacy/ShipmentsApi.php index d8540e5..0d2ed98 100644 --- a/src/Api/ShipmentsApi.php +++ b/src/Api/Legacy/ShipmentsApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/ShipmentsApiInterface.php b/src/Api/Legacy/ShipmentsApiInterface.php similarity index 86% rename from src/Api/ShipmentsApiInterface.php rename to src/Api/Legacy/ShipmentsApiInterface.php index d22448e..e94f403 100644 --- a/src/Api/ShipmentsApiInterface.php +++ b/src/Api/Legacy/ShipmentsApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; diff --git a/src/Api/ShippingCategoriesApi.php b/src/Api/Legacy/ShippingCategoriesApi.php similarity index 95% rename from src/Api/ShippingCategoriesApi.php rename to src/Api/Legacy/ShippingCategoriesApi.php index 59b1d97..771a377 100644 --- a/src/Api/ShippingCategoriesApi.php +++ b/src/Api/Legacy/ShippingCategoriesApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/ShippingCategoriesApiInterface.php b/src/Api/Legacy/ShippingCategoriesApiInterface.php similarity index 82% rename from src/Api/ShippingCategoriesApiInterface.php rename to src/Api/Legacy/ShippingCategoriesApiInterface.php index 283f348..79c486d 100644 --- a/src/Api/ShippingCategoriesApiInterface.php +++ b/src/Api/Legacy/ShippingCategoriesApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; diff --git a/src/Api/TaxCategoriesApi.php b/src/Api/Legacy/TaxCategoriesApi.php similarity index 96% rename from src/Api/TaxCategoriesApi.php rename to src/Api/Legacy/TaxCategoriesApi.php index bb3136b..bd71386 100644 --- a/src/Api/TaxCategoriesApi.php +++ b/src/Api/Legacy/TaxCategoriesApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/TaxCategoriesApiInterface.php b/src/Api/Legacy/TaxCategoriesApiInterface.php similarity index 87% rename from src/Api/TaxCategoriesApiInterface.php rename to src/Api/Legacy/TaxCategoriesApiInterface.php index 731aa98..3e2dd98 100644 --- a/src/Api/TaxCategoriesApiInterface.php +++ b/src/Api/Legacy/TaxCategoriesApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; diff --git a/src/Api/TaxRatesApi.php b/src/Api/Legacy/TaxRatesApi.php similarity index 95% rename from src/Api/TaxRatesApi.php rename to src/Api/Legacy/TaxRatesApi.php index 41a062b..559fca3 100644 --- a/src/Api/TaxRatesApi.php +++ b/src/Api/Legacy/TaxRatesApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/TaxRatesApiInterface.php b/src/Api/Legacy/TaxRatesApiInterface.php similarity index 82% rename from src/Api/TaxRatesApiInterface.php rename to src/Api/Legacy/TaxRatesApiInterface.php index 50be7df..cc5746a 100644 --- a/src/Api/TaxRatesApiInterface.php +++ b/src/Api/Legacy/TaxRatesApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; diff --git a/src/Api/TaxonsApi.php b/src/Api/Legacy/TaxonsApi.php similarity index 96% rename from src/Api/TaxonsApi.php rename to src/Api/Legacy/TaxonsApi.php index 5b9e3e0..8de5c45 100644 --- a/src/Api/TaxonsApi.php +++ b/src/Api/Legacy/TaxonsApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/TaxonsApiInterface.php b/src/Api/Legacy/TaxonsApiInterface.php similarity index 86% rename from src/Api/TaxonsApiInterface.php rename to src/Api/Legacy/TaxonsApiInterface.php index dd7b16b..3bfef08 100644 --- a/src/Api/TaxonsApiInterface.php +++ b/src/Api/Legacy/TaxonsApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; diff --git a/src/Api/UsersApi.php b/src/Api/Legacy/UsersApi.php similarity index 96% rename from src/Api/UsersApi.php rename to src/Api/Legacy/UsersApi.php index 681fbe0..fcfdef0 100644 --- a/src/Api/UsersApi.php +++ b/src/Api/Legacy/UsersApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/UsersApiInterface.php b/src/Api/Legacy/UsersApiInterface.php similarity index 86% rename from src/Api/UsersApiInterface.php rename to src/Api/Legacy/UsersApiInterface.php index 558fff3..9fd0c84 100644 --- a/src/Api/UsersApiInterface.php +++ b/src/Api/Legacy/UsersApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; diff --git a/src/Api/ZonesApi.php b/src/Api/Legacy/ZonesApi.php similarity index 96% rename from src/Api/ZonesApi.php rename to src/Api/Legacy/ZonesApi.php index eeb82ab..1c0e206 100644 --- a/src/Api/ZonesApi.php +++ b/src/Api/Legacy/ZonesApi.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; diff --git a/src/Api/ZonesApiInterface.php b/src/Api/Legacy/ZonesApiInterface.php similarity index 86% rename from src/Api/ZonesApiInterface.php rename to src/Api/Legacy/ZonesApiInterface.php index 9100e5e..845c16e 100644 --- a/src/Api/ZonesApiInterface.php +++ b/src/Api/Legacy/ZonesApiInterface.php @@ -9,8 +9,9 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; diff --git a/src/Api/Operation/CreatableResourceInterface.php b/src/Api/Operation/CreatableResourceInterface.php index d9366eb..20011c0 100644 --- a/src/Api/Operation/CreatableResourceInterface.php +++ b/src/Api/Operation/CreatableResourceInterface.php @@ -17,13 +17,13 @@ interface CreatableResourceInterface /** * Creates a resource. * - * @param string $code code of the resource to create - * @param array $data data of the resource to create + * @param string|int $code code of the resource to create + * @param array $data data of the resource to create * * @throws HttpException if the request failed * @throws InvalidArgumentException if the parameter "code" is defined in the data parameter * * @return int status code 201 indicating that the resource has been well created */ - public function create($code, array $data = []); + public function create($code, array $data = []): int; } diff --git a/src/Api/Operation/DeletableDoubleResourceInterface.php b/src/Api/Operation/DeletableDoubleResourceInterface.php index 632b41f..4af5a0a 100644 --- a/src/Api/Operation/DeletableDoubleResourceInterface.php +++ b/src/Api/Operation/DeletableDoubleResourceInterface.php @@ -9,12 +9,12 @@ interface DeletableDoubleResourceInterface /** * Deletes a resource. * - * @param mixed $code code of the parent resource - * @param mixed $id code or id of the resource to get + * @param string|int $code code of the parent resource + * @param string|int $id code or id of the resource to get * * @throws HttpException * * @return int status code 204 indicating that the resource has been well deleted */ - public function delete($code, $id); + public function delete($code, string|int $id): int; } diff --git a/src/Api/Operation/DeletableResourceInterface.php b/src/Api/Operation/DeletableResourceInterface.php index d514138..6bfabaa 100644 --- a/src/Api/Operation/DeletableResourceInterface.php +++ b/src/Api/Operation/DeletableResourceInterface.php @@ -16,11 +16,11 @@ interface DeletableResourceInterface /** * Deletes a resource. * - * @param mixed $code code or id of the resource to delete + * @param string|int $code code or id of the resource to delete * * @throws HttpException * * @return int status code 204 indicating that the resource has been well deleted */ - public function delete($code); + public function delete($code): int; } diff --git a/src/Api/Operation/DownloadableResourceInterface.php b/src/Api/Operation/DownloadableResourceInterface.php index a21a548..d1c059d 100644 --- a/src/Api/Operation/DownloadableResourceInterface.php +++ b/src/Api/Operation/DownloadableResourceInterface.php @@ -17,11 +17,11 @@ interface DownloadableResourceInterface /** * Downloads a resource by its code. * - * @param string $code Code of the resource + * @param string|int $code Code of the resource * * @throws HttpException * * @return StreamInterface */ - public function download($code); + public function download($code): StreamInterface; } diff --git a/src/Api/Operation/GettableDoubleResourceInterface.php b/src/Api/Operation/GettableDoubleResourceInterface.php index bd3523c..594a98f 100644 --- a/src/Api/Operation/GettableDoubleResourceInterface.php +++ b/src/Api/Operation/GettableDoubleResourceInterface.php @@ -9,12 +9,10 @@ interface GettableDoubleResourceInterface /** * Gets a resource by its code. * - * @param mixed $code code of the parent resource - * @param mixed $id code or id of the resource to get + * @param string|int $code code of the parent resource + * @param string|int $id code or id of the resource to get * * @throws HttpException if the request failed - * - * @return array */ - public function get($code, $id); + public function get($code, $id): array; } diff --git a/src/Api/Operation/GettableResourceInterface.php b/src/Api/Operation/GettableResourceInterface.php index decf67c..39ae6d6 100644 --- a/src/Api/Operation/GettableResourceInterface.php +++ b/src/Api/Operation/GettableResourceInterface.php @@ -16,11 +16,9 @@ interface GettableResourceInterface /** * Gets a resource by its code. * - * @param string $code Code of the resource + * @param string|int $code Code of the resource * * @throws HttpException if the request failed - * - * @return array */ - public function get($code); + public function get($code): array; } diff --git a/src/Api/Operation/ListableDoubleResourceInterface.php b/src/Api/Operation/ListableDoubleResourceInterface.php index 377103a..2e6ad52 100644 --- a/src/Api/Operation/ListableDoubleResourceInterface.php +++ b/src/Api/Operation/ListableDoubleResourceInterface.php @@ -14,7 +14,7 @@ interface ListableDoubleResourceInterface * Gets a list of resources by returning the first page. * Consequently, this method does not return all the resources. * - * @param mixed $code code of the parent resource + * @param string|int $code code of the parent resource * @param int $limit The maximum number of resources to return. * Do note that the server has a maximum limit allowed. * @param array $queryParameters additional query parameters to pass in the request @@ -24,28 +24,28 @@ interface ListableDoubleResourceInterface * @return PageInterface */ public function listPerPage( - string $code, - $limit = 10, + $code, + int $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ); + ): PageInterface; /** * Gets a cursor to iterate over a list of resources. * - * @param mixed $code code of the parent resource - * @param int $pageSize The size of the page returned by the server. - * Do note that the server has a maximum limit allowed. - * @param array $queryParameters Additional query parameters to pass in the request + * @param string|int $code code of the parent resource + * @param int $pageSize The size of the page returned by the server. + * Do note that the server has a maximum limit allowed. + * @param array $queryParameters Additional query parameters to pass in the request * * @return ResourceCursorInterface */ public function all( - string $code, - $pageSize = 10, + $code, + int $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ); + ): ResourceCursorInterface; } diff --git a/src/Api/Operation/ListableResourceInterface.php b/src/Api/Operation/ListableResourceInterface.php index 692b346..481b188 100644 --- a/src/Api/Operation/ListableResourceInterface.php +++ b/src/Api/Operation/ListableResourceInterface.php @@ -30,11 +30,11 @@ interface ListableResourceInterface * @return PageInterface */ public function listPerPage( - $limit = 10, + int $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ); + ): PageInterface; /** * Gets a cursor to iterate over a list of resources. @@ -46,9 +46,9 @@ public function listPerPage( * @return ResourceCursorInterface */ public function all( - $pageSize = 10, + int $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ); + ): ResourceCursorInterface; } diff --git a/src/Api/Operation/UpsertableResourceInterface.php b/src/Api/Operation/UpsertableResourceInterface.php index 13d9956..5ebe4ef 100644 --- a/src/Api/Operation/UpsertableResourceInterface.php +++ b/src/Api/Operation/UpsertableResourceInterface.php @@ -16,7 +16,7 @@ interface UpsertableResourceInterface /** * Creates a resource if it does not exist yet, otherwise updates partially the resource. * - * @param string $code code of the resource to create or update + * @param string|int $code code of the resource to create or update * @param array $data data of the resource to create or update * * @throws HttpException if the request failed @@ -24,5 +24,5 @@ interface UpsertableResourceInterface * @return int Status code 201 indicating that the resource has been well created. * Status code 204 indicating that the resource has been well updated. */ - public function upsert($code, array $data = []); + public function upsert($code, array $data = []): int; } diff --git a/src/Api/Operation/UpsertableResourceListInterface.php b/src/Api/Operation/UpsertableResourceListInterface.php index ec69ecf..464b118 100644 --- a/src/Api/Operation/UpsertableResourceListInterface.php +++ b/src/Api/Operation/UpsertableResourceListInterface.php @@ -23,5 +23,5 @@ interface UpsertableResourceListInterface * * @return \Traversable returns an iterable object, each entry corresponding to the response of the upserted resource */ - public function upsertList($resources); + public function upsertList(array|StreamInterface $resources): \Traversable; } diff --git a/src/Api/Shop/AddressApi.php b/src/Api/Shop/AddressApi.php new file mode 100644 index 0000000..ac45ea5 --- /dev/null +++ b/src/Api/Shop/AddressApi.php @@ -0,0 +1,67 @@ +resourceClient->getResource('api/v2/shop/addresses/%s'); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/shop/addresses'); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function create($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->createResource('api/v2/shop/addresses', [], $data); + } + + public function upsert($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->upsertResource('api/v2/shop/addresses/%d', [$code], $data); + } + + public function delete($code): int + { + Assert::integer($code); + return $this->resourceClient->deleteResource('api/v2/shop/addresses/%d', [$code]); + } +} diff --git a/src/Api/Shop/AddressApiInterface.php b/src/Api/Shop/AddressApiInterface.php new file mode 100644 index 0000000..a385157 --- /dev/null +++ b/src/Api/Shop/AddressApiInterface.php @@ -0,0 +1,13 @@ +resourceClient->getResource('api/v2/shop/adjustments/%d'); + } + + public function listPerPage( + $code, + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + Assert::string($code); + $data = $this->resourceClient->getResources('api/v2/shop/orders/%s/adjustments', [$code]); + + return $this->pageFactory->createPage($data); + } + + public function all( + $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } +} diff --git a/src/Api/Shop/AdjustmentApiInterface.php b/src/Api/Shop/AdjustmentApiInterface.php new file mode 100644 index 0000000..7f72e92 --- /dev/null +++ b/src/Api/Shop/AdjustmentApiInterface.php @@ -0,0 +1,10 @@ +resourceClient->getResource('api/v2/shop/channels/%d'); + } +} diff --git a/src/Api/Shop/ChannelApiInterface.php b/src/Api/Shop/ChannelApiInterface.php new file mode 100644 index 0000000..5d30953 --- /dev/null +++ b/src/Api/Shop/ChannelApiInterface.php @@ -0,0 +1,9 @@ +resourceClient->getResource('api/v2/shop/countries/%d', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/shop/countries', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } +} diff --git a/src/Api/Shop/CountryApiInterface.php b/src/Api/Shop/CountryApiInterface.php new file mode 100644 index 0000000..7cd19cd --- /dev/null +++ b/src/Api/Shop/CountryApiInterface.php @@ -0,0 +1,10 @@ + + * @copyright 2017 Akeneo SAS (http://www.akeneo.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ +class LegacyAuthenticatedHttpClient implements HttpClientInterface +{ + public function __construct( + private HttpClient $basicHttpClient, + private Api\Legacy\AuthenticationApiInterface $authenticationApi, + private LegacyAuthentication $authentication, + ) {} + + /** + * {@inheritdoc} + */ + public function sendRequest($httpMethod, $uri, array $headers = [], $body = null) + { + try { + $xauthtokenDetected = false; + foreach ((array) $this->authentication->getXauthtokenHeader() as $name => $value) { + $headers[$name] = $value; + $xauthtokenDetected = true; + } + + if ($xauthtokenDetected) { + return $this->basicHttpClient->sendRequest($httpMethod, $uri, $headers, $body); + } + } catch (UnauthorizedHttpException $e) { + // Do nothing and process to standard authentication + } + + if (null === $this->authentication->getAccessToken()) { + $tokens = $this->authenticationApi->authenticateByPassword( + $this->authentication->getClientId(), + $this->authentication->getSecret(), + $this->authentication->getUsername(), + $this->authentication->getPassword() + ); + + $this->authentication + ->setAccessToken($tokens['access_token']) + ->setRefreshToken($tokens['refresh_token']) + ; + } + + try { + $headers['Authorization'] = sprintf('Bearer %s', $this->authentication->getAccessToken()); + $response = $this->basicHttpClient->sendRequest($httpMethod, $uri, $headers, $body); + } catch (UnauthorizedHttpException $e) { + $tokens = $this->authenticationApi->authenticateByRefreshToken( + $this->authentication->getClientId(), + $this->authentication->getSecret(), + $this->authentication->getRefreshToken() + ); + + $this->authentication + ->setAccessToken($tokens['access_token']) + ->setRefreshToken($tokens['refresh_token']) + ; + + $headers['Authorization'] = sprintf('Bearer %s', $this->authentication->getAccessToken()); + $response = $this->basicHttpClient->sendRequest($httpMethod, $uri, $headers, $body); + } + + return $response; + } +} diff --git a/src/ClientBuilderInterface.php b/src/ClientBuilderInterface.php new file mode 100644 index 0000000..d7839d2 --- /dev/null +++ b/src/ClientBuilderInterface.php @@ -0,0 +1,21 @@ + + * @copyright 2017 Akeneo SAS (http://www.akeneo.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ +class LegacyAuthentication +{ + private ?string $clientId; + private ?string $secret; + private ?string $username; + private ?string $password; + private ?string $accessToken; + private ?string $refreshToken; + protected array $xauthtokenHeader; + + public static function fromPassword(string $clientId, string $secret, string $username, string $password): self + { + $authentication = new static(); + $authentication->clientId = $clientId; + $authentication->secret = $secret; + $authentication->username = $username; + $authentication->password = $password; + + return $authentication; + } + + public static function fromToken(string $clientId, string $secret, string $accessToken, string $refreshToken): self + { + $authentication = new static(); + $authentication->clientId = $clientId; + $authentication->secret = $secret; + $authentication->accessToken = $accessToken; + $authentication->refreshToken = $refreshToken; + + return $authentication; + } + + public static function fromXAuthToken(array $fromXAuthToken): self + { + $authentication = new static(); + $authentication->xauthtokenHeader = $fromXAuthToken; + + return $authentication; + } + + public function getClientId(): ?string + { + return $this->clientId; + } + + public function getSecret(): ?string + { + return $this->secret; + } + + public function getUsername(): ?string + { + return $this->username; + } + + public function getPassword(): ?string + { + return $this->password; + } + + public function getAccessToken(): ?string + { + return $this->accessToken; + } + + public function getRefreshToken(): ?string + { + return $this->refreshToken; + } + + public function setAccessToken(string $accessToken): self + { + $this->accessToken = $accessToken; + + return $this; + } + + public function setRefreshToken(string $refreshToken): self + { + $this->refreshToken = $refreshToken; + + return $this; + } + + public function getXauthtokenHeader(): ?array + { + return $this->xauthtokenHeader; + } +} diff --git a/src/SyliusAdminClient.php b/src/SyliusAdminClient.php new file mode 100644 index 0000000..3680bc7 --- /dev/null +++ b/src/SyliusAdminClient.php @@ -0,0 +1,73 @@ +addressApi; + } + + public function getAdjustmentApi(): Api\Admin\AdjustmentApiInterface + { + return $this->adjustmentApi; + } + + public function getAdministratorApi(): Api\Admin\AdministratorApiInterface + { + return $this->administratorApi; + } + + public function getAvatarImageApi(): Api\Admin\AvatarImageApiInterface + { + return $this->avatarImageApi; + } + + public function getCatalogPromotionTranslationApi(): Api\Admin\CatalogPromotionTranslationApiInterface + { + return $this->catalogPromotionTranslationApi; + } + + public function getCatalogPromotionApi(): Api\Admin\CatalogPromotionApiInterface + { + return $this->catalogPromotionApi; + } + + public function getChannelApi(): Api\Admin\ChannelApiInterface + { + return $this->channelApi; + } + + public function getShopBillingDataApi(): Api\Admin\ShopBillingDataApiInterface + { + return $this->shopBillingDataApi; + } + + public function getCountryApi(): Api\Admin\CountryApiInterface + { + return $this->countryApi; + } + + public function getProvinceApi(): Api\Admin\ProvinceApiInterface + { + return $this->provinceApi; + } +} diff --git a/src/SyliusAdminClientBuilderInterface.php b/src/SyliusAdminClientBuilderInterface.php new file mode 100644 index 0000000..eb58372 --- /dev/null +++ b/src/SyliusAdminClientBuilderInterface.php @@ -0,0 +1,15 @@ + */ + private array $apiRegistry = []; + + public function __construct( + private SyliusAdminClientInterface $decoratedClient + ) {} + + public function __call($name, $arguments) + { + $property = lcfirst(substr($name, 3)); + if ('get' === substr($name, 0, 3) && isset($this->apiRegistry[$property])) { + return $this->apiRegistry[$property]; + } + + return $this->decoratedClient->{$name}($arguments); + } + + public function addApi(string $key, Api\ApiAwareInterface $api) + { + $this->apiRegistry[$key] = $api; + } + + public function get(string $name): ?Api\ApiAwareInterface + { + return $this->apiRegistry[$name] ?? null; + } + + public function getAddressApi(): Api\Admin\AddressApiInterface + { + return $this->decoratedClient->getAddressApi(); + } + + public function getAdjustmentApi(): Api\Admin\AdjustmentApiInterface + { + return $this->decoratedClient->getAdjustmentApi(); + } + + public function getAdministratorApi(): Api\Admin\AdministratorApiInterface + { + return $this->decoratedClient->getAdministratorApi(); + } + + public function getAvatarImageApi(): Api\Admin\AvatarImageApiInterface + { + return $this->decoratedClient->getAvatarImageApi(); + } + + public function getCatalogPromotionTranslationApi(): Api\Admin\CatalogPromotionTranslationApiInterface + { + return $this->decoratedClient->getCatalogPromotionTranslationApi(); + } + + public function getCatalogPromotionApi(): Api\Admin\CatalogPromotionApiInterface + { + return $this->decoratedClient->getCatalogPromotionApi(); + } + + public function getChannelApi(): Api\Admin\ChannelApiInterface + { + return $this->decoratedClient->getChannelApi(); + } + + public function getShopBillingDataApi(): Api\Admin\ShopBillingDataApiInterface + { + return $this->decoratedClient->getShopBillingDataApi(); + } + + public function getCountryApi(): Api\Admin\CountryApiInterface + { + return $this->decoratedClient->getCountryApi(); + } + + public function getProvinceApi(): Api\Admin\ProvinceApiInterface + { + return $this->decoratedClient->getProvinceApi(); + } +} diff --git a/src/SyliusAdminClientInterface.php b/src/SyliusAdminClientInterface.php new file mode 100644 index 0000000..3a0b1bc --- /dev/null +++ b/src/SyliusAdminClientInterface.php @@ -0,0 +1,19 @@ + - * - * @category SyliusApiClient - * - * @copyright 2020 - Diglin (https://www.diglin.com) - */ - -namespace Diglin\Sylius\ApiClient; - -use Diglin\Sylius\ApiClient\Api; -use Diglin\Sylius\ApiClient\Security\Authentication; - -class SyliusClient implements SyliusClientInterface -{ - /** @var Authentication */ - private $authentication; - - /** @var Api\ChannelsApiInterface */ - private $channelsApi; - /** @var Api\UsersApiInterface */ - private $usersApi; - /** @var Api\CustomersApiInterface */ - private $customersApi; - /** @var Api\ProductsApiInterface */ - private $productsApi; - /** @var Api\CartsApiInterface */ - private $cartsApi; - /** @var Api\OrdersApiInterface */ - private $ordersApi; - /** @var Api\PaymentsApiInterface */ - private $paymentsApi; - /** @var Api\ShipmentsApiInterface */ - private $shipmentsApi; - /** @var Api\ShippingCategoriesApiInterface */ - private $shippingCategoriesApi; - /** @var Api\LocalesApiInterface */ - private $localesApi; - /** @var Api\CurrenciesApiInterface */ - private $currenciesApi; - /** @var Api\CountriesApiInterface */ - private $countriesApi; - /** @var Api\ExchangeRatesApiInterface */ - private $exchangeRatesApi; - /** @var Api\PaymentMethodsApiInterface */ - private $paymentMethodsApi; - /** @var Api\ProductAttributesApiInterface */ - private $productAttributesApi; - /** @var Api\ProductAssociationTypesApiInterface */ - private $productAssociationTypesApi; - /** @var Api\ProductOptionsApiInterface */ - private $productOptionsApi; - /** @var Api\ProductReviewsApiInterface */ - private $productReviewsApi; - /** @var Api\ProductVariantsApiInterface */ - private $productVariantsApi; - /** @var Api\PromotionsApiInterface */ - private $promotionsApi; - /** @var Api\PromotionCouponsApiInterface */ - private $promotionCouponsApi; - /** @var Api\TaxCategoriesApiInterface */ - private $taxCategoriesApi; - /** @var Api\TaxRatesApiInterface */ - private $taxRatesApi; - /** @var Api\TaxonsApiInterface */ - private $taxonsApi; - /** @var Api\ZonesApiInterface */ - private $zonesApi; - - public function __construct( - Authentication $authentication, - Api\CartsApiInterface $cartsApi, - Api\ChannelsApiInterface $channelsApi, - Api\CountriesApiInterface $countriesApi, - Api\CurrenciesApiInterface $currenciesApi, - Api\CustomersApiInterface $customersApi, - Api\ExchangeRatesApiInterface $exchangeRatesApi, - Api\LocalesApiInterface $localesApi, - Api\OrdersApiInterface $ordersApi, - Api\PaymentMethodsApiInterface $paymentMethodApi, - Api\PaymentsApiInterface $paymentsApi, - Api\ProductsApiInterface $productsApi, - Api\ProductAttributesApiInterface $productAttributesApi, - Api\ProductAssociationTypesApiInterface $productAssociationTypesApi, - Api\ProductOptionsApiInterface $productOptionsApi, - Api\ProductReviewsApiInterface $productReviewsApi, - Api\ProductVariantsApiInterface $productVariantsApi, - Api\PromotionsApiInterface $promotionsApi, - Api\PromotionCouponsApiInterface $promotionCouponsApi, - Api\ShipmentsApiInterface $shipmentsApi, - Api\ShippingCategoriesApiInterface $shippingCategoriesApi, - Api\TaxCategoriesApiInterface $taxCategoriesApi, - Api\TaxRatesApiInterface $taxRatesApi, - Api\TaxonsApiInterface $taxonsApi, - Api\UsersApiInterface $usersApi, - Api\ZonesApiInterface $zonesApi - ) { - $this->authentication = $authentication; - $this->channelsApi = $channelsApi; - $this->usersApi = $usersApi; - $this->customersApi = $customersApi; - $this->productsApi = $productsApi; - $this->cartsApi = $cartsApi; - $this->ordersApi = $ordersApi; - $this->paymentsApi = $paymentsApi; - $this->shipmentsApi = $shipmentsApi; - $this->shippingCategoriesApi = $shippingCategoriesApi; - $this->localesApi = $localesApi; - $this->currenciesApi = $currenciesApi; - $this->countriesApi = $countriesApi; - $this->exchangeRatesApi = $exchangeRatesApi; - $this->paymentMethodsApi = $paymentMethodApi; - $this->productAttributesApi = $productAttributesApi; - $this->productAssociationTypesApi = $productAssociationTypesApi; - $this->productOptionsApi = $productOptionsApi; - $this->productReviewsApi = $productReviewsApi; - $this->productVariantsApi = $productVariantsApi; - $this->promotionsApi = $promotionsApi; - $this->promotionCouponsApi = $promotionCouponsApi; - $this->taxCategoriesApi = $taxCategoriesApi; - $this->taxRatesApi = $taxRatesApi; - $this->taxonsApi = $taxonsApi; - $this->zonesApi = $zonesApi; - } - - public function getZonesApi(): Api\ZonesApiInterface - { - return $this->zonesApi; - } - - public function getTaxonsApi(): Api\TaxonsApiInterface - { - return $this->taxonsApi; - } - - public function getTaxRatesApi(): Api\TaxRatesApiInterface - { - return $this->taxRatesApi; - } - - public function getTaxCategoriesApi(): Api\TaxCategoriesApiInterface - { - return $this->taxCategoriesApi; - } - - public function getPromotionCouponsApi(): Api\PromotionCouponsApiInterface - { - return $this->promotionCouponsApi; - } - - public function getPromotionsApi(): Api\PromotionsApiInterface - { - return $this->promotionsApi; - } - - public function getProductVariantsApi(): Api\ProductVariantsApiInterface - { - return $this->productVariantsApi; - } - - public function getProductReviewsApi(): Api\ProductReviewsApiInterface - { - return $this->productReviewsApi; - } - - public function getProductOptionsApi(): Api\ProductOptionsApiInterface - { - return $this->productOptionsApi; - } - public function getProductAssociationTypesApi(): Api\ProductAssociationTypesApiInterface - { - return $this->productAssociationTypesApi; - } +declare(strict_types=1); - public function getProductAttributesApi(): Api\ProductAttributesApiInterface - { - return $this->productAttributesApi; - } +use Diglin\Sylius\ApiClient; - public function getShippingCategoriesApi(): Api\ShippingCategoriesApi - { - return $this->shippingCategoriesApi; - } +trigger_deprecation('diglin/sylius-api-php-client', '2.0', 'The "%s" class is deprecated, use "%s" instead.', 'Diglin\\Sylius\\ApiClient\\SyliusClient', ApiClient\SyliusLegacyClient::class); - public function getLocalesApi(): Api\LocalesApiInterface - { - return $this->localesApi; - } - - public function getCurrenciesApi(): Api\CurrenciesApiInterface - { - return $this->currenciesApi; - } - - public function getCountriesApi(): Api\CountriesApiInterface - { - return $this->countriesApi; - } - - public function getExchangeRatesApi(): Api\ExchangeRatesApiInterface - { - return $this->exchangeRatesApi; - } - - public function getPaymentMethodsApi(): Api\PaymentMethodsApiInterface - { - return $this->paymentMethodsApi; - } - - public function getUsersApi(): Api\UsersApiInterface - { - return $this->usersApi; - } - - public function getCustomersApi(): Api\CustomersApiInterface - { - return $this->customersApi; - } - - public function getProductsApi(): Api\ProductsApiInterface - { - return $this->productsApi; - } - - public function getCartsApi(): Api\CartsApiInterface - { - return $this->cartsApi; - } - - public function getOrdersApi(): Api\OrdersApiInterface - { - return $this->ordersApi; - } - - public function getPaymentsApi(): Api\PaymentsApiInterface - { - return $this->paymentsApi; - } - - public function getShipmentsApi(): Api\ShipmentsApiInterface - { - return $this->shipmentsApi; - } - - public function getToken(): ?string - { - return $this->authentication->getAccessToken(); - } - - public function getRefreshToken(): ?string - { - return $this->authentication->getRefreshToken(); - } - - public function getChannelsApi(): Api\ChannelsApiInterface - { - return $this->channelsApi; - } -} +/** + * @deprecated since diglin/sylius-api-php-client 2.0, use Diglin\Sylius\ApiClient\ApiClient\SyliusLegacyClient instead. + */ +class_alias(ApiClient\SyliusLegacyClient::class, 'Diglin\\Sylius\\ApiClient\\SyliusClient'); diff --git a/src/SyliusClientBuilder.php b/src/SyliusClientBuilder.php index 6577b11..7c66eb4 100644 --- a/src/SyliusClientBuilder.php +++ b/src/SyliusClientBuilder.php @@ -1,262 +1,12 @@ - * - * @category SyliusApiClient - * - * @copyright 2020 - Diglin (https://www.diglin.com) - */ -namespace Diglin\Sylius\ApiClient; +declare(strict_types=1); + +use Diglin\Sylius\ApiClient; -use Diglin\Sylius\ApiClient\Api; -use Diglin\Sylius\ApiClient\Client\AuthenticatedHttpClient; -use Diglin\Sylius\ApiClient\Client\HttpClient; -use Diglin\Sylius\ApiClient\Client\ResourceClient; -use Diglin\Sylius\ApiClient\FileSystem\FileSystemInterface; -use Diglin\Sylius\ApiClient\FileSystem\LocalFileSystem; -use Diglin\Sylius\ApiClient\Pagination\PageFactory; -use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactory; -use Diglin\Sylius\ApiClient\Routing\UriGenerator; -use Diglin\Sylius\ApiClient\Security\Authentication; -use Diglin\Sylius\ApiClient\Stream\MultipartStreamBuilderFactory; -use Diglin\Sylius\ApiClient\Stream\UpsertResourceListResponseFactory; -use Http\Client\HttpClient as Client; -use Http\Discovery\HttpClientDiscovery; -use Http\Discovery\Psr17FactoryDiscovery; -use Http\Message\RequestFactory; -use Http\Message\StreamFactory; -use Psr\Http\Message\RequestFactoryInterface; -use Psr\Http\Message\StreamFactoryInterface; +trigger_deprecation('diglin/sylius-api-php-client', '2.0', 'The "%s" class is deprecated, use "%s" instead.', 'Diglin\\Sylius\\ApiClient\\SyliusClientBuilder', ApiClient\SyliusSyliusLegacyClientFactory::class); /** - * Builder of the class SyliusClient. - * This builder is in charge to instantiate and inject the dependencies. - * - * @author Alexandre Hocquard - * @author Sylvain Rayé - * @copyright 2017 Akeneo SAS (http://www.akeneo.com) - * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @deprecated since diglin/sylius-api-php-client 2.0, use Diglin\Sylius\ApiClient\ApiClient\SyliusLegacyClientBuilder instead. */ -class SyliusClientBuilder implements SyliusClientBuilderInterface -{ - /** @var string */ - protected $baseUri; - - /** @var Client */ - protected $httpClient; - - /** @var RequestFactory */ - protected $requestFactory; - - /** @var StreamFactory */ - protected $streamFactory; - - /** @var FileSystemInterface */ - protected $fileSystem; - - /** @var Api\ApiAwareInterface[] */ - protected $apiRegistry = []; - - /** @var array */ - protected $defaultHeaders = []; - - public function __construct(?Api\ApiAwareInterface ...$apis) - { - foreach ($apis as $api) { - $this->addApi($api); - } - } - - /** - * @return array - */ - protected function setUp(Authentication $authentication) - { - $uriGenerator = new UriGenerator($this->baseUri); - $httpClient = new HttpClient($this->getHttpClient(), $this->getRequestFactory(), $this->getStreamFactory(), $this->defaultHeaders); - - $authenticationApi = new Api\AuthenticationApi($httpClient, $uriGenerator); - $authenticatedHttpClient = new AuthenticatedHttpClient($httpClient, $authenticationApi, $authentication); - $multipartStreamBuilderFactory = new MultipartStreamBuilderFactory($this->getStreamFactory()); - $upsertListResponseFactory = new UpsertResourceListResponseFactory(); - - $resourceClient = new ResourceClient( - $authenticatedHttpClient, - $uriGenerator, - $multipartStreamBuilderFactory, - $upsertListResponseFactory - ); - - $pageFactory = new PageFactory($authenticatedHttpClient, $uriGenerator); - $cursorFactory = new ResourceCursorFactory(); - $fileSystem = null !== $this->fileSystem ? $this->fileSystem : new LocalFileSystem(); - - return [$resourceClient, $pageFactory, $cursorFactory, $fileSystem]; - } - - public function addApi(Api\ApiAwareInterface $api): self - { - $this->apiRegistry[(new \ReflectionClass($api))->getShortName()] = $api; - - return $this; - } - - public function setBaseUri(string $baseUri): SyliusClientBuilderInterface - { - $this->baseUri = $baseUri; - - return $this; - } - - public function setDefaultHeaders(array $headers): SyliusClientBuilderInterface - { - $this->defaultHeaders = $headers; - - return $this; - } - - /** - * Allows to directly set a client instead of using HttpClientDiscovery::find(). - */ - public function setHttpClient(Client $httpClient): SyliusClientBuilderInterface - { - $this->httpClient = $httpClient; - - return $this; - } - - /** - * Allows to directly set a request factory instead of using MessageFactoryDiscovery::find(). - */ - public function setRequestFactory(RequestFactory $requestFactory): SyliusClientBuilderInterface - { - $this->requestFactory = $requestFactory; - - return $this; - } - - /** - * Allows to directly set a stream factory instead of using StreamFactoryDiscovery::find(). - */ - public function setStreamFactory(StreamFactory $streamFactory): SyliusClientBuilderInterface - { - $this->streamFactory = $streamFactory; - - return $this; - } - - /** - * Build the Sylius client authenticated by user name and password. - */ - public function buildAuthenticatedByPassword( - string $clientId, - string $secret, - string $username, - string $password - ): SyliusClientInterface { - $authentication = Authentication::fromPassword($clientId, $secret, $username, $password); - - return $this->buildAuthenticatedClient($authentication); - } - - /** - * Build the Sylius client authenticated by token. - */ - public function buildAuthenticatedByToken( - string $clientId, - string $secret, - string $token, - string $refreshToken - ): SyliusClientInterface { - $authentication = Authentication::fromToken($clientId, $secret, $token, $refreshToken); - - return $this->buildAuthenticatedClient($authentication); - } - - /** - * Build the Sylius client authenticated by HTTP header. - */ - public function buildAuthenticatedByHeader(array $xAuthToken): SyliusClientInterface - { - $authentication = Authentication::fromXAuthToken($xAuthToken); - - return $this->buildAuthenticatedClient($authentication); - } - - private function buildAuthenticatedClient(Authentication $authentication): SyliusClientInterface - { - [$resourceClient, $pageFactory, $cursorFactory, $fileSystem] = $this->setUp($authentication); - - $client = new SyliusClientDecorator( - new SyliusClient( - $authentication, - new Api\CartsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ChannelsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\CountriesApi($resourceClient, $pageFactory, $cursorFactory), - new Api\CurrenciesApi($resourceClient, $pageFactory, $cursorFactory), - new Api\CustomersApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ExchangeRatesApi($resourceClient, $pageFactory, $cursorFactory), - new Api\LocalesApi($resourceClient, $pageFactory, $cursorFactory), - new Api\OrdersApi($resourceClient, $pageFactory, $cursorFactory), - new Api\PaymentMethodsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\PaymentsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ProductsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ProductAttributesApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ProductAssociationTypesApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ProductOptionsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ProductReviewsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ProductVariantsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\PromotionsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\PromotionCouponsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ShipmentsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ShippingCategoriesApi($resourceClient, $pageFactory, $cursorFactory), - new Api\TaxCategoriesApi($resourceClient, $pageFactory, $cursorFactory), - new Api\TaxRatesApi($resourceClient, $pageFactory, $cursorFactory), - new Api\TaxonsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\UsersApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ZonesApi($resourceClient, $pageFactory, $cursorFactory) - ) - ); - - foreach ($this->apiRegistry as $key => $api) { - $api->setResourceClient($resourceClient); - $api->setPageFactory($pageFactory); - $api->setCursorFactory($cursorFactory); - $api->setFileSystem($fileSystem); - - $client->addApi($key, $api); - } - - return $client; - } - - private function getHttpClient(): Client - { - if (null === $this->httpClient) { - $this->httpClient = HttpClientDiscovery::find(); - } - - return $this->httpClient; - } - - private function getRequestFactory(): RequestFactoryInterface - { - if (null === $this->requestFactory) { - $this->requestFactory = Psr17FactoryDiscovery::findRequestFactory(); - } - - return $this->requestFactory; - } - - private function getStreamFactory(): StreamFactoryInterface - { - if (null === $this->streamFactory) { - $this->streamFactory = Psr17FactoryDiscovery::findStreamFactory(); - } - - return $this->streamFactory; - } -} +class_alias(ApiClient\SyliusSyliusLegacyClientFactory::class, 'Diglin\\Sylius\\ApiClient\\SyliusClientBuilder'); diff --git a/src/SyliusClientBuilderInterface.php b/src/SyliusClientBuilderInterface.php index ce62942..b75d0d1 100644 --- a/src/SyliusClientBuilderInterface.php +++ b/src/SyliusClientBuilderInterface.php @@ -1,43 +1,12 @@ - * @category FWG OroCRM - * @copyright 2020 - Diglin (https://www.diglin.com) - */ - -namespace Diglin\Sylius\ApiClient; - -use Http\Client\HttpClient as Client; -use Http\Message\RequestFactory; -use Http\Message\StreamFactory; - -interface SyliusClientBuilderInterface -{ - public function setBaseUri(string $baseUri): self; - public function setDefaultHeaders(array $headers): self; +declare(strict_types=1); - public function setHttpClient(Client $httpClient): self; +use Diglin\Sylius\ApiClient; - public function setRequestFactory(RequestFactory $requestFactory): self; +trigger_deprecation('diglin/sylius-api-php-client', '2.0', 'The "%s" interface is deprecated, use "%s" instead.', 'Diglin\\Sylius\\ApiClient\\SyliusClientBuilderInterface', ApiClient\SyliusLegacyClientInterface::class); - public function setStreamFactory(StreamFactory $streamFactory): self; - - public function buildAuthenticatedByPassword( - string $clientId, - string $secret, - string $username, - string $password - ): SyliusClientInterface; - - public function buildAuthenticatedByToken( - string $clientId, - string $secret, - string $token, - string $refreshToken - ): SyliusClientInterface; - - public function buildAuthenticatedByHeader(array $xAuthToken): SyliusClientInterface; -} +/** + * @deprecated since diglin/sylius-api-php-client 2.0, use Diglin\Sylius\ApiClient\ApiClient\SyliusLegacyClientBuilderInterface instead. + */ +class_alias(ApiClient\SyliusLegacyClientBuilderInterface::class, 'Diglin\\Sylius\\ApiClient\\SyliusClientBuilderInterface'); diff --git a/src/SyliusClientInterface.php b/src/SyliusClientInterface.php index 68581ab..de9b9ab 100644 --- a/src/SyliusClientInterface.php +++ b/src/SyliusClientInterface.php @@ -1,92 +1,12 @@ + * + * @category SyliusApiClient + * + * @copyright 2020 - Diglin (https://www.diglin.com) + */ + +namespace Diglin\Sylius\ApiClient; + +use Diglin\Sylius\ApiClient\Api\Legacy as Api; +use Diglin\Sylius\ApiClient\Security\LegacyAuthentication; + +class SyliusLegacyClient implements SyliusLegacyClientInterface +{ + public function __construct( + private LegacyAuthentication $authentication, + private Api\CartsApiInterface $cartsApi, + private Api\ChannelsApiInterface $channelsApi, + private Api\CountriesApiInterface $countriesApi, + private Api\CurrenciesApiInterface $currenciesApi, + private Api\CustomersApiInterface $customersApi, + private Api\ExchangeRatesApiInterface $exchangeRatesApi, + private Api\LocalesApiInterface $localesApi, + private Api\OrdersApiInterface $ordersApi, + private Api\PaymentMethodsApiInterface $paymentMethodsApi, + private Api\PaymentsApiInterface $paymentsApi, + private Api\ProductsApiInterface $productsApi, + private Api\ProductAttributesApiInterface $productAttributesApi, + private Api\ProductAssociationTypesApiInterface $productAssociationTypesApi, + private Api\ProductOptionsApiInterface $productOptionsApi, + private Api\ProductReviewsApiInterface $productReviewsApi, + private Api\ProductVariantsApiInterface $productVariantsApi, + private Api\PromotionsApiInterface $promotionsApi, + private Api\PromotionCouponsApiInterface $promotionCouponsApi, + private Api\ShipmentsApiInterface $shipmentsApi, + private Api\ShippingCategoriesApiInterface $shippingCategoriesApi, + private Api\TaxCategoriesApiInterface $taxCategoriesApi, + private Api\TaxRatesApiInterface $taxRatesApi, + private Api\TaxonsApiInterface $taxonsApi, + private Api\UsersApiInterface $usersApi, + private Api\ZonesApiInterface $zonesApi + ) {} + + public function getZonesApi(): Api\ZonesApiInterface + { + return $this->zonesApi; + } + + public function getTaxonsApi(): Api\TaxonsApiInterface + { + return $this->taxonsApi; + } + + public function getTaxRatesApi(): Api\TaxRatesApiInterface + { + return $this->taxRatesApi; + } + + public function getTaxCategoriesApi(): Api\TaxCategoriesApiInterface + { + return $this->taxCategoriesApi; + } + + public function getPromotionCouponsApi(): Api\PromotionCouponsApiInterface + { + return $this->promotionCouponsApi; + } + + public function getPromotionsApi(): Api\PromotionsApiInterface + { + return $this->promotionsApi; + } + + public function getProductVariantsApi(): Api\ProductVariantsApiInterface + { + return $this->productVariantsApi; + } + + public function getProductReviewsApi(): Api\ProductReviewsApiInterface + { + return $this->productReviewsApi; + } + + public function getProductOptionsApi(): Api\ProductOptionsApiInterface + { + return $this->productOptionsApi; + } + + public function getProductAssociationTypesApi(): Api\ProductAssociationTypesApiInterface + { + return $this->productAssociationTypesApi; + } + + public function getProductAttributesApi(): Api\ProductAttributesApiInterface + { + return $this->productAttributesApi; + } + + public function getShippingCategoriesApi(): Api\ShippingCategoriesApiInterface + { + return $this->shippingCategoriesApi; + } + + public function getLocalesApi(): Api\LocalesApiInterface + { + return $this->localesApi; + } + + public function getCurrenciesApi(): Api\CurrenciesApiInterface + { + return $this->currenciesApi; + } + + public function getCountriesApi(): Api\CountriesApiInterface + { + return $this->countriesApi; + } + + public function getExchangeRatesApi(): Api\ExchangeRatesApiInterface + { + return $this->exchangeRatesApi; + } + + public function getPaymentMethodsApi(): Api\PaymentMethodsApiInterface + { + return $this->paymentMethodsApi; + } + + public function getUsersApi(): Api\UsersApiInterface + { + return $this->usersApi; + } + + public function getCustomersApi(): Api\CustomersApiInterface + { + return $this->customersApi; + } + + public function getProductsApi(): Api\ProductsApiInterface + { + return $this->productsApi; + } + + public function getCartsApi(): Api\CartsApiInterface + { + return $this->cartsApi; + } + + public function getOrdersApi(): Api\OrdersApiInterface + { + return $this->ordersApi; + } + + public function getPaymentsApi(): Api\PaymentsApiInterface + { + return $this->paymentsApi; + } + + public function getShipmentsApi(): Api\ShipmentsApiInterface + { + return $this->shipmentsApi; + } + + public function getChannelsApi(): Api\ChannelsApiInterface + { + return $this->channelsApi; + } + + public function getToken(): ?string + { + return $this->authentication->getAccessToken(); + } + + public function getRefreshToken(): ?string + { + return $this->authentication->getRefreshToken(); + } +} diff --git a/src/SyliusLegacyClientBuilderInterface.php b/src/SyliusLegacyClientBuilderInterface.php new file mode 100644 index 0000000..855bf21 --- /dev/null +++ b/src/SyliusLegacyClientBuilderInterface.php @@ -0,0 +1,27 @@ +decoratedClient = $decoratedClient; } diff --git a/src/SyliusLegacyClientInterface.php b/src/SyliusLegacyClientInterface.php new file mode 100644 index 0000000..769e558 --- /dev/null +++ b/src/SyliusLegacyClientInterface.php @@ -0,0 +1,68 @@ +addressApi; + } + + public function getAdjustmentApi(): Api\Shop\AdjustmentApiInterface + { + return $this->adjustmentApi; + } + + public function getChannelApi(): Api\Shop\ChannelApiInterface + { + return $this->channelApi; + } + + public function getCountryApi(): Api\Shop\CountryApiInterface + { + return $this->countryApi; + } +} diff --git a/src/SyliusShopClientBuilderInterface.php b/src/SyliusShopClientBuilderInterface.php new file mode 100644 index 0000000..974ff8a --- /dev/null +++ b/src/SyliusShopClientBuilderInterface.php @@ -0,0 +1,15 @@ + */ + private array $apiRegistry = []; + + public function __construct( + private SyliusShopClientInterface $decoratedClient + ) {} + + public function __call($name, $arguments) + { + $property = lcfirst(substr($name, 3)); + if ('get' === substr($name, 0, 3) && isset($this->apiRegistry[$property])) { + return $this->apiRegistry[$property]; + } + + return $this->decoratedClient->{$name}($arguments); + } + + public function addApi(string $key, Api\ApiAwareInterface $api) + { + $this->apiRegistry[$key] = $api; + } + + public function get(string $name): ?Api\ApiAwareInterface + { + return $this->apiRegistry[$name] ?? null; + } + + public function getAddressApi(): Api\Shop\AddressApiInterface + { + return $this->decoratedClient->getAddressApi(); + } + + public function getAdjustmentApi(): Api\Shop\AdjustmentApiInterface + { + return $this->decoratedClient->getAdjustmentApi(); + } + + public function getChannelApi(): Api\Shop\ChannelApiInterface + { + return $this->decoratedClient->getChannelApi(); + } + + public function getCountryApi(): Api\Shop\CountryApiInterface + { + return $this->decoratedClient->getCountryApi(); + } +} diff --git a/src/SyliusShopClientInterface.php b/src/SyliusShopClientInterface.php new file mode 100644 index 0000000..76303ac --- /dev/null +++ b/src/SyliusShopClientInterface.php @@ -0,0 +1,13 @@ + */ + private array $apiRegistry = []; + /** @var array */ + private array $defaultHeaders = []; + + public function __construct(Api\ApiAwareInterface ...$apis) + { + array_map(fn (Api\ApiAwareInterface $api) => $this->addApi($api), $apis); + } + + public function addApi(Api\ApiAwareInterface $api): self + { + $this->apiRegistry[(new \ReflectionClass($api))->getShortName()] = $api; + + return $this; + } + + public function setBaseUri(string $baseUri): self + { + $this->baseUri = $baseUri; + + return $this; + } + + public function setDefaultHeaders(array $headers): self + { + $this->defaultHeaders = $headers; + + return $this; + } + + /** + * Allows to directly set a client instead of using HttpClientDiscovery::find(). + */ + public function setHttpClient(Client $httpClient): self + { + $this->httpClient = $httpClient; + + return $this; + } + + /** + * Allows to directly set a request factory instead of using MessageFactoryDiscovery::find(). + */ + public function setRequestFactory(RequestFactoryInterface $requestFactory): self + { + $this->requestFactory = $requestFactory; + + return $this; + } + + /** + * Allows to directly set a stream factory instead of using StreamFactoryDiscovery::find(). + */ + public function setStreamFactory(StreamFactoryInterface $streamFactory): self + { + $this->streamFactory = $streamFactory; + + return $this; + } + + /** + * Build the Sylius client authenticated by user name and password. + */ + public function buildAuthenticatedByPassword( + string $username, + string $password + ): SyliusAdminClientInterface { + $authentication = Authentication::fromPassword($username, $password); + + return $this->buildAuthenticatedClient($authentication); + } + + /** + * Build the Sylius client authenticated by token. + */ + public function buildAuthenticatedByToken( + string $token, + ): SyliusAdminClientInterface { + $authentication = Authentication::fromAccessToken($token); + + return $this->buildAuthenticatedClient($authentication); + } + + private function buildAuthenticatedClient(Authentication $authentication): SyliusAdminClientInterface + { + $uriGenerator = new UriGenerator($this->baseUri); + $httpClient = new HttpClient($this->getHttpClient(), $this->getRequestFactory(), $this->getStreamFactory(), $this->defaultHeaders); + + $authenticationApi = new Api\Authentication\AdminApi($httpClient, $uriGenerator); + $authenticatedHttpClient = new AuthenticatedHttpClient($httpClient, $authenticationApi, $authentication); + $multipartStreamBuilderFactory = new MultipartStreamBuilderFactory($this->getStreamFactory()); + $upsertListResponseFactory = new UpsertResourceListResponseFactory(); + + $resourceClient = new ResourceClient( + $authenticatedHttpClient, + $uriGenerator, + $multipartStreamBuilderFactory, + $upsertListResponseFactory + ); + + $pageFactory = new PageFactory($authenticatedHttpClient, $uriGenerator); + $cursorFactory = new ResourceCursorFactory(); + $fileSystem = null !== $this->fileSystem ? $this->fileSystem : new LocalFileSystem(); + + $client = new SyliusAdminClientDecorator( + new SyliusAdminClient( + $authentication, + new Api\Admin\AddressApi($resourceClient), + new Api\Admin\AdjustmentApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\AdministratorApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\AvatarImageApi($resourceClient), + new Api\Admin\CatalogPromotionTranslationApi($resourceClient), + new Api\Admin\CatalogPromotionApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ChannelApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ShopBillingDataApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\CountryApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ProvinceApi($resourceClient, $pageFactory, $cursorFactory), + ) + ); + + foreach ($this->apiRegistry as $key => $api) { + $api->setResourceClient($resourceClient); + $api->setPageFactory($pageFactory); + $api->setCursorFactory($cursorFactory); + $api->setFileSystem($fileSystem); + + $client->addApi($key, $api); + } + + return $client; + } + + private function getHttpClient(): Client + { + if (null === $this->httpClient) { + $this->httpClient = HttpClientDiscovery::find(); + } + + return $this->httpClient; + } + + private function getRequestFactory(): RequestFactoryInterface + { + if (null === $this->requestFactory) { + $this->requestFactory = Psr17FactoryDiscovery::findRequestFactory(); + } + + return $this->requestFactory; + } + + private function getStreamFactory(): StreamFactoryInterface + { + if (null === $this->streamFactory) { + $this->streamFactory = Psr17FactoryDiscovery::findStreamFactory(); + } + + return $this->streamFactory; + } +} diff --git a/src/SyliusSyliusLegacyClientFactory.php b/src/SyliusSyliusLegacyClientFactory.php new file mode 100644 index 0000000..1da579d --- /dev/null +++ b/src/SyliusSyliusLegacyClientFactory.php @@ -0,0 +1,249 @@ + + * + * @category SyliusApiClient + * + * @copyright 2020 - Diglin (https://www.diglin.com) + */ + +namespace Diglin\Sylius\ApiClient; + +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; +use Diglin\Sylius\ApiClient\Api\Legacy as Api; +use Diglin\Sylius\ApiClient\Client\AuthenticatedHttpClient; +use Diglin\Sylius\ApiClient\Client\HttpClient; +use Diglin\Sylius\ApiClient\Client\ResourceClient; +use Diglin\Sylius\ApiClient\FileSystem\FileSystemInterface; +use Diglin\Sylius\ApiClient\FileSystem\LocalFileSystem; +use Diglin\Sylius\ApiClient\Pagination\PageFactory; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactory; +use Diglin\Sylius\ApiClient\Routing\UriGenerator; +use Diglin\Sylius\ApiClient\Security\LegacyAuthentication; +use Diglin\Sylius\ApiClient\Stream\MultipartStreamBuilderFactory; +use Diglin\Sylius\ApiClient\Stream\UpsertResourceListResponseFactory; +use Http\Client\HttpClient as Client; +use Http\Discovery\HttpClientDiscovery; +use Http\Discovery\Psr17FactoryDiscovery; +use Psr\Http\Message\RequestFactoryInterface; +use Psr\Http\Message\StreamFactoryInterface; + +/** + * Builder of the class SyliusClient. + * This builder is in charge to instantiate and inject the dependencies. + * + * @author Alexandre Hocquard + * @author Sylvain Rayé + * @copyright 2017 Akeneo SAS (http://www.akeneo.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ +class SyliusSyliusLegacyClientFactory implements SyliusLegacyClientBuilderInterface +{ + private ?string $baseUri; + private Client $httpClient; + private RequestFactoryInterface $requestFactory; + private StreamFactoryInterface $streamFactory; + private FileSystemInterface $fileSystem; + /** @var list */ + private array $apiRegistry = []; + private array $defaultHeaders = []; + + public function __construct(?ApiAwareInterface ...$apis) + { + foreach ($apis as $api) { + $this->addApi($api); + } + } + + /** + * @return array + */ + protected function setUp(LegacyAuthentication $authentication) + { + $uriGenerator = new UriGenerator($this->baseUri); + $httpClient = new HttpClient($this->getHttpClient(), $this->getRequestFactory(), $this->getStreamFactory(), $this->defaultHeaders); + + $authenticationApi = new Api\AuthenticationApi($httpClient, $uriGenerator); + $authenticatedHttpClient = new AuthenticatedHttpClient($httpClient, $authenticationApi, $authentication); + $multipartStreamBuilderFactory = new MultipartStreamBuilderFactory($this->getStreamFactory()); + $upsertListResponseFactory = new UpsertResourceListResponseFactory(); + + $resourceClient = new ResourceClient( + $authenticatedHttpClient, + $uriGenerator, + $multipartStreamBuilderFactory, + $upsertListResponseFactory + ); + + $pageFactory = new PageFactory($authenticatedHttpClient, $uriGenerator); + $cursorFactory = new ResourceCursorFactory(); + $fileSystem = null !== $this->fileSystem ? $this->fileSystem : new LocalFileSystem(); + + return [$resourceClient, $pageFactory, $cursorFactory, $fileSystem]; + } + + public function addApi(ApiAwareInterface $api) + { + $this->apiRegistry[(new \ReflectionClass($api))->getShortName()] = $api; + } + + public function setBaseUri(string $baseUri): self + { + $this->baseUri = $baseUri; + + return $this; + } + + public function setDefaultHeaders(array $headers): self + { + $this->defaultHeaders = $headers; + + return $this; + } + + /** + * Allows to directly set a client instead of using HttpClientDiscovery::find(). + */ + public function setHttpClient(Client $httpClient): self + { + $this->httpClient = $httpClient; + + return $this; + } + + /** + * Allows to directly set a request factory instead of using MessageFactoryDiscovery::find(). + */ + public function setRequestFactory(RequestFactoryInterface $requestFactory): self + { + $this->requestFactory = $requestFactory; + + return $this; + } + + /** + * Allows to directly set a stream factory instead of using StreamFactoryDiscovery::find(). + */ + public function setStreamFactory(StreamFactoryInterface $streamFactory): self + { + $this->streamFactory = $streamFactory; + + return $this; + } + + /** + * Build the Sylius client authenticated by user name and password. + */ + public function buildAuthenticatedByPassword( + string $clientId, + string $secret, + string $username, + string $password, + ): SyliusLegacyClientInterface { + $authentication = LegacyAuthentication::fromPassword($clientId, $secret, $username, $password); + + return $this->buildAuthenticatedClient($authentication); + } + + /** + * Build the Sylius client authenticated by token. + */ + public function buildAuthenticatedByToken( + string $clientId, + string $secret, + string $token, + string $refreshToken, + ): SyliusLegacyClientInterface { + $authentication = LegacyAuthentication::fromToken($clientId, $secret, $token, $refreshToken); + + return $this->buildAuthenticatedClient($authentication); + } + + /** + * Build the Sylius client authenticated by HTTP header. + */ + public function buildAuthenticatedByHeader( + array $xAuthToken, + ): SyliusLegacyClientInterface { + $authentication = LegacyAuthentication::fromXAuthToken($xAuthToken); + + return $this->buildAuthenticatedClient($authentication); + } + + private function buildAuthenticatedClient( + LegacyAuthentication $authentication + ): SyliusLegacyClientInterface { + [$resourceClient, $pageFactory, $cursorFactory, $fileSystem] = $this->setUp($authentication); + + $client = new SyliusLegacyClientDecorator( + new SyliusLegacyClient( + $authentication, + new Api\CartsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ChannelsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\CountriesApi($resourceClient, $pageFactory, $cursorFactory), + new Api\CurrenciesApi($resourceClient, $pageFactory, $cursorFactory), + new Api\CustomersApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ExchangeRatesApi($resourceClient, $pageFactory, $cursorFactory), + new Api\LocalesApi($resourceClient, $pageFactory, $cursorFactory), + new Api\OrdersApi($resourceClient, $pageFactory, $cursorFactory), + new Api\PaymentMethodsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\PaymentsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ProductsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ProductAttributesApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ProductAssociationTypesApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ProductOptionsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ProductReviewsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ProductVariantsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\PromotionsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\PromotionCouponsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ShipmentsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ShippingCategoriesApi($resourceClient, $pageFactory, $cursorFactory), + new Api\TaxCategoriesApi($resourceClient, $pageFactory, $cursorFactory), + new Api\TaxRatesApi($resourceClient, $pageFactory, $cursorFactory), + new Api\TaxonsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\UsersApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ZonesApi($resourceClient, $pageFactory, $cursorFactory) + ) + ); + + foreach ($this->apiRegistry as $key => $api) { + $api->setResourceClient($resourceClient); + $api->setPageFactory($pageFactory); + $api->setCursorFactory($cursorFactory); + $api->setFileSystem($fileSystem); + + $client->addApi($key, $api); + } + + return $client; + } + + private function getHttpClient(): Client + { + if (null === $this->httpClient) { + $this->httpClient = HttpClientDiscovery::find(); + } + + return $this->httpClient; + } + + private function getRequestFactory(): RequestFactoryInterface + { + if (null === $this->requestFactory) { + $this->requestFactory = Psr17FactoryDiscovery::findRequestFactory(); + } + + return $this->requestFactory; + } + + private function getStreamFactory(): StreamFactoryInterface + { + if (null === $this->streamFactory) { + $this->streamFactory = Psr17FactoryDiscovery::findStreamFactory(); + } + + return $this->streamFactory; + } +} diff --git a/src/SyliusSyliusShopClientBuilder.php b/src/SyliusSyliusShopClientBuilder.php new file mode 100644 index 0000000..53af7db --- /dev/null +++ b/src/SyliusSyliusShopClientBuilder.php @@ -0,0 +1,183 @@ + */ + private array $apiRegistry = []; + /** @var array */ + private array $defaultHeaders = []; + + public function __construct(Api\ApiAwareInterface ...$apis) + { + array_map(fn (Api\ApiAwareInterface $api) => $this->addApi($api), $apis); + } + + public function addApi(Api\ApiAwareInterface $api): self + { + $this->apiRegistry[(new \ReflectionClass($api))->getShortName()] = $api; + + return $this; + } + + public function setBaseUri(string $baseUri): self + { + $this->baseUri = $baseUri; + + return $this; + } + + public function setDefaultHeaders(array $headers): self + { + $this->defaultHeaders = $headers; + + return $this; + } + + /** + * Allows to directly set a client instead of using HttpClientDiscovery::find(). + */ + public function setHttpClient(Client $httpClient): self + { + $this->httpClient = $httpClient; + + return $this; + } + + /** + * Allows to directly set a request factory instead of using MessageFactoryDiscovery::find(). + */ + public function setRequestFactory(RequestFactoryInterface $requestFactory): self + { + $this->requestFactory = $requestFactory; + + return $this; + } + + /** + * Allows to directly set a stream factory instead of using StreamFactoryDiscovery::find(). + */ + public function setStreamFactory(StreamFactoryInterface $streamFactory): self + { + $this->streamFactory = $streamFactory; + + return $this; + } + + /** + * Build the Sylius client authenticated by user name and password. + */ + public function buildAuthenticatedByPassword( + string $username, + string $password + ): SyliusShopClientInterface { + $authentication = Authentication::fromPassword($username, $password); + + return $this->buildAuthenticatedClient($authentication); + } + + /** + * Build the Sylius client authenticated by token. + */ + public function buildAuthenticatedByToken( + string $token, + ): SyliusShopClientInterface { + $authentication = Authentication::fromAccessToken($token); + + return $this->buildAuthenticatedClient($authentication); + } + + private function buildAuthenticatedClient(Authentication $authentication): SyliusShopClientInterface + { + $uriGenerator = new UriGenerator($this->baseUri); + $httpClient = new HttpClient($this->getHttpClient(), $this->getRequestFactory(), $this->getStreamFactory(), $this->defaultHeaders); + + $authenticationApi = new Api\Authentication\AdminApi($httpClient, $uriGenerator); + $authenticatedHttpClient = new AuthenticatedHttpClient($httpClient, $authenticationApi, $authentication); + $multipartStreamBuilderFactory = new MultipartStreamBuilderFactory($this->getStreamFactory()); + $upsertListResponseFactory = new UpsertResourceListResponseFactory(); + + $resourceClient = new ResourceClient( + $authenticatedHttpClient, + $uriGenerator, + $multipartStreamBuilderFactory, + $upsertListResponseFactory + ); + + $pageFactory = new PageFactory($authenticatedHttpClient, $uriGenerator); + $cursorFactory = new ResourceCursorFactory(); + $fileSystem = null !== $this->fileSystem ? $this->fileSystem : new LocalFileSystem(); + + $client = new SyliusShopClientDecorator( + new SyliusShopClient( + $authentication, + new Api\Shop\AddressApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\AdjustmentApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\ChannelApi($resourceClient), + new Api\Shop\CountryApi($resourceClient, $pageFactory, $cursorFactory), + ) + ); + + foreach ($this->apiRegistry as $key => $api) { + $api->setResourceClient($resourceClient); + $api->setPageFactory($pageFactory); + $api->setCursorFactory($cursorFactory); + $api->setFileSystem($fileSystem); + + $client->addApi($key, $api); + } + + return $client; + } + + private function getHttpClient(): Client + { + if (null === $this->httpClient) { + $this->httpClient = HttpClientDiscovery::find(); + } + + return $this->httpClient; + } + + private function getRequestFactory(): RequestFactoryInterface + { + if (null === $this->requestFactory) { + $this->requestFactory = Psr17FactoryDiscovery::findRequestFactory(); + } + + return $this->requestFactory; + } + + private function getStreamFactory(): StreamFactoryInterface + { + if (null === $this->streamFactory) { + $this->streamFactory = Psr17FactoryDiscovery::findStreamFactory(); + } + + return $this->streamFactory; + } +}