esign/laravel-plytix
Composer 安装命令:
composer require esign/laravel-plytix
包简介
A Laravel SDK for the Plytix API
README 文档
README
This package allow you to easily interact with the Plytix API.
Installation
You can install the package via composer:
composer require esign/laravel-plytix
The package will automatically register a service provider.
Next up, you can publish the configuration file:
php artisan vendor:publish --provider="Esign\Plytix\PlytixServiceProvider" --tag="config"
The config file will be published as config/plytix.php with the following content:
<?php return [ /** * The API key to be used for authenticating with the Plytix API. */ 'api_key' => env('PLYTIX_API_KEY'), /** * The API password to be used for authenticating with the Plytix API. */ 'api_password' => env('PLYTIX_API_PASSWORD'), 'authenticator_cache' => [ /** * The key that will be used to cache the Plytix access token. */ 'key' => 'esign.plytix.authenticator', /** * The cache store to be used for the Plytix access token. * Use null to utilize the default cache store from the cache.php config file. * To disable caching, you can use the 'array' store. */ 'store' => null, ], 'rate_limiting' => [ /** * The cache store to be used for the Plytix rate limits. * Use null to utilize the default cache store from the cache.php config file. * To disable caching, you can use the 'array' store. */ 'cache_store' => null, ], ];
Usage
This package leverages Saloon for sending requests to the Plytix API, providing an elegant way to interact with the API.
Authentication
After configuring your API key and password in the config file, authentication tokens are automatically managed by the package. There's no need to manually handle authentication tokens.
Rate limiting
The Plytix API enforces rate limits based on the subscription plan you’re on.
You can configure these rate limits in the boot method of your AppServiceProvider:
use Esign\Plytix\Facades\RateLimiter; use Saloon\RateLimitPlugin\Limit; public function boot(): void { RateLimiter::setLimits( Limit::allow(20)->everySeconds(10), Limit::allow(5000)->everyHour(), ); }
Sending requests
To send requests to the Plytix API, you may use the Esign\Plytix\Plytix connector.
You can explore all the available request classes in the src/Requests directory.
Each version of the Plytix API, such as V1 or V2, has its own folder. Note that some requests are only accessible in certain versions.
Here’s an example of sending a request:
use Esign\Plytix\Plytix; use Esign\Plytix\Requests\V2\ProductRequest; class MyCommand { public function handle(): int { $plytix = Plytix::make(); $response = $plytix->send(new ProductRequest('583bef16-2197-46dd-90ce-9f4210bef5ef')); return self::SUCCESS; } }
Response handling
This package uses DTOs (Data Transfer Objects) to simplify working with API responses. You can retrieve the DTO from the response like this:
$plytix = Plytix::make(); $response = $plytix->send(new ProductRequest('583bef16-2197-46dd-90ce-9f4210bef5ef')); $product = $response->dtoOrFail();
Alternatively, you can retrieve the raw response data:
$plytix = Plytix::make(); $response = $plytix->send(new ProductRequest('583bef16-2197-46dd-90ce-9f4210bef5ef')); $data = $response->body();
Paginating requests
For endpoints that return paginated data, you can easily paginate through the responses:
$plytix = Plytix::make(); $paginator = $plytix->paginate(new ProductSearchRequest()); foreach ($paginator as $response) { $products = $response->dtoOrFail(); }
Additionally, you may also traverse through these pages using the items or collect methods.
For more information, refer to the Saloon pagination documentation.
$plytix = Plytix::make(); $paginator = $plytix->paginate(new ProductSearchRequest()); foreach ($paginator->items() as $product) { // Do something with the product } $paginator->collect()->each(function ($product) { // Do something with the product });
Creating requests
Extending existing requests
If you need to customize or extend an existing request, you can create your own request class by extending the base request class:
use Esign\Plytix\Requests\ProductRequest; class MyCustomProductRequest extends ProductRequest { protected function defaultQuery(): array { return [ 'customer-query-param' => 'value', ]; } }
Creating custom requests
If the request you need is not provided by the package, you can create a custom request using Saloon. First, install the Saloon Laravel plugin, then use the following command:
php artisan saloon:request Plytix MyCustomRequest
use Saloon\Enums\Method; use Saloon\Http\Request; class MyCustomRequest extends Request { protected Method $method = Method::GET; public function resolveEndpoint(): string { return '/example'; } }
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.
esign/laravel-plytix 适用场景与选型建议
esign/laravel-plytix 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.38k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 09 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「esign」 「plytix」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 esign/laravel-plytix 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 esign/laravel-plytix 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 esign/laravel-plytix 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A laravel package to make your eloquent models translatable.
Manage SEO tags within your Laravel application
Load translations from the database or other sources.
Associate files with your Laravel Models
Generate slugs when saving UnderscoreTranslatable models
Throttle exceptions being sent to Sentry
统计信息
- 总下载量: 2.38k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-18