sandwave-io / f-secure
用于 F-Secure API 的 HTTP 客户端。
1.4.0
2023-05-09 08:20 UTC
Requires
- php: ^8.1
- ext-json: *
- guzzlehttp/guzzle: ^7.5.0
- jms/serializer-bundle: ^5.2.1
Requires (Dev)
- ergebnis/phpstan-rules: ^1.0.0
- friendsofphp/php-cs-fixer: ^3.14.4
- phpstan/extension-installer: ^1.2.0
- phpstan/phpstan: ^1.10.6
- phpstan/phpstan-deprecation-rules: ^1.1.2
- phpstan/phpstan-phpunit: ^1.3.10
- phpstan/phpstan-strict-rules: ^1.5.0
- phpunit/phpunit: ^10.0.15
- sandwave-io/php-cs-fixer-config: ^1.0.0
- spaze/phpstan-disallowed-calls: ^2.12.0
- thecodingmachine/phpstan-strict-rules: ^1.0.0
README
F-secure API 客户端
如何使用(API)
composer require sandwave-io/f-secure
<?php require "vendor/autoload.php"; use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy; use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; use JMS\Serializer\SerializerBuilder; use SandwaveIo\FSecure\Client\Client; use SandwaveIo\FSecure\Client\AuthClient; use SandwaveIo\FSecure\Client\OrderClient; use SandwaveIo\FSecure\Client\ProductClient; use SandwaveIo\FSecure\HttpClient\AuthenticatedClientFactory; use SandwaveIo\FSecure\HttpClient\BearerTokenMiddleware; use SandwaveIo\FSecure\HttpClient\ClientFactory; use SandwaveIo\FSecure\Service\ThrowableConvertor; $apiEndpoint = 'https://vip.f-secure.com/api/v2/'; $clientId = 'client_id'; $clientSecret = 'client_secret'; // create AuthClient $auth = new AuthClient( $clientId, $clientSecret, (new ClientFactory($apiEndpoint))->create(), (new SerializerBuilder())->build(), new ThrowableConvertor() ); // use AuthClient to create a GuzzleClient binded with middleware for handling the bearer token $httpClient = (new AuthenticatedClientFactory( $apiEndpoint, new BearerTokenMiddleware($auth) ))->create(); // create client by injecting the guzzleclient $client = new Client( $httpClient, (new SerializerBuilder())->setPropertyNamingStrategy( new SerializedNameAnnotationStrategy( new IdenticalPropertyNamingStrategy() ) )->build(), new ThrowableConvertor() ); // use client to create ProductClient $productClient = new ProductClient($client); $productCollection = $productClient->get(); // or use client to create OrderClient $orderClient = new OrderClient($client); $orderCollection = $orderClient->get();
如何贡献
如果您有任何改进想法,请随时创建一个 PR。或者创建一个问题。
- 添加代码时,请确保为它添加测试(phpunit)。
- 确保代码遵循我们的编码标准(使用 php-cs-fixer 进行检查/修复)。
- 同时确保 PHPStan 找不到任何错误。
composer analyze # this will (dry)run php-cs-fixer, phpstan and phpunit composer phpcs-fix # this will actually let php-cs-fixer run to fix
这些工具也会在 GitHub actions 中在主分支的 PR 和推送时运行。