randock/vignette-api-client
Composer 安装命令:
composer require randock/vignette-api-client
包简介
Vignette PHP api client
README 文档
README
The API works by obtaining a JWT and then sending it to the api. In order to speed things up, we need to store the JWT response by implementing the persistence strategy.
The easiest way is to use a PSR-16 compatible cache adapter. Most frameworks have these.
See https://github.com/eljam/guzzle-jwt-middleware#persistence
Minimum required code to use the API:
<?php use Softonic\GraphQL\Client; use Softonic\GraphQL\ResponseBuilder; use Randock\Vignette\Api\Client\ApiClient; use Randock\Vignette\Api\Util\ClientBuilder; use Randock\Vignette\Api\Client\Object\Enum\OrderStatus; use Randock\Vignette\Api\Client\Object\Input\ListOrdersInput; // This example uses "null" as persistence strategy. DO NOT DO THIS IN PROD. $client = new Client( ClientBuilder::newClient( 'ENDPOINT', 'JWT_ENDPOINT', [ 'username' => 'XXX', 'password' => 'XXX' ], null ), new ResponseBuilder() ); // The API is strongly typed, so all responses are easy to use. // You need to select all fields that you are going to use in the response. // The API uses GRAPHQL underneath, so not selecting a field means it won't be available. // See the docs for all possible fields. $apiClient = new ApiClient($client); $ordersResponse = $apiClient->orders( [ 'paging' => ['total'], 'orders' => ['id', 'status'] ], new ListOrdersInput(1, 10, null, null) ); // The total number of orders can be found in the paging section. echo sprintf( "Found %d orders\n\n", $ordersResponse->getPaging()->getTotal() ); // Loop through the orders and print some data. foreach ($ordersResponse->getOrders() as $order) { echo sprintf( "Status of order %s is %s. Order is completed: %d\n", $order->getId(), $order->getStatus(), $order->getStatus() === OrderStatus::COMPLETED ); } // If you try to access a field that you didn't request, an exception is thrown. // FieldNotSelectedException: The field orderId has not been selected in the query. Add it to the query if you need it. echo $ordersResponse->getOrders()[0]->getOrderId();
randock/vignette-api-client 适用场景与选型建议
randock/vignette-api-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 05 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 randock/vignette-api-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 randock/vignette-api-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2021-05-14