gdinko/prim
Composer 安装命令:
composer require gdinko/prim
包简介
Laravel Prim API Wrapper
README 文档
README
Installation
You can install the package via composer:
composer require gdinko/prim
If you plan to use database for storing request / error logs:
php artisan migrate --step
If you need to export configuration file:
php artisan vendor:publish --tag=prim-config
If you need to export migrations:
php artisan vendor:publish --tag=prim-migrations
If you need to export models:
php artisan vendor:publish --tag=prim-models
If you need to export commands:
php artisan vendor:publish --tag=prim-commands
Configuration
Add this to .env file:
PRIM_API_TOKEN= #Get API token from prim.bg PRIM_API_BASE_URL= #Get API Base URL from prim.bg PRIM_API_TIMEOUT= #default 30 PRIM_ENABLE_REQUEST_LOG=true/false #default false | log every request/response in database PRIM_ENABLE_ERROR_LOG=true/false #default true | log every error response in database
Usage
Runtime Setup
Prim::setApiToken('token'); Prim::getApiToken(); Prim::setBaseUrl('endpoint'); Prim::getBaseUrl(); Prim::setTimeout(99); Prim::getTimeout(); Prim::enableRequestLog(); Prim::disableRequestLog(); Prim::enableErrorLog(); Prim::disableErrorLog();
Methods
//list all API methods and params Prim::getAllMethods(): array //get info about method params Prim::getMethodParams($method, $verb): array //auto generate validation rules for API method Prim::getValidationRules($method, $verb): array //make call to custom METHOD Prim::public function customMethod(string $methodName, PrimRequestInterface $request, string $verb = 'post', $wantAll = false) /** * getAccounts * * Prim Endpoint: RPC.common.Api.Accounts.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getAccounts(PrimRequestInterface $request, $wantAll = false): array /** * setAddresses * * Prim Endpoint: RPC.common.Api.Addresses.set * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::setAddresses(PrimRequestInterface $request, $wantAll = false): array /** * getExpenseAllocations * * Prim Endpoint: RPC.common.Api.Allocations.getExpense * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getExpenseAllocations(PrimRequestInterface $request, $wantAll = false): array /** * getAvailabilities * * Prim Endpoint: RPC.common.Api.Availabilities.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getAvailabilities(PrimRequestInterface $request, $wantAll = false): array /** * getAvailabilitiesByLabels * * Prim Endpoint: RPC.common.Api.AvailabilitiesByLabels.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getAvailabilitiesByLabels(PrimRequestInterface $request, $wantAll = false): array /** * getBlanks * * Prim Endpoint: RPC.common.Api.Blanks.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getBlanks(PrimRequestInterface $request, $wantAll = false): array /** * getBonusPoints * * Prim Endpoint: RPC.common.Api.BonusPoints.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getBonusPoints(PrimRequestInterface $request, $wantAll = false): array /** * setBrands * * Prim Endpoint: RPC.common.Api.Brands.set * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::setBrands(PrimRequestInterface $request, $wantAll = false): array /** * getClientTypes * * Prim Endpoint: RPC.common.Api.ClientTypes.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getClientTypes(PrimRequestInterface $request, $wantAll = false): array /** * setContacts * * Prim Endpoint: RPC.common.Api.Contacts.set * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::setContacts(PrimRequestInterface $request, $wantAll = false): array /** * getCurrencies * * Prim Endpoint: RPC.common.Api.Currencies.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getCurrencies(PrimRequestInterface $request, $wantAll = false): array /** * getDeliveryTypes * * Prim Endpoint: RPC.common.Api.DeliveryTypes.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getDeliveryTypes(PrimRequestInterface $request, $wantAll = false): array /** * getDocInfo * * Prim Endpoint: RPC.common.Api.DocInfo.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getDocInfo(PrimRequestInterface $request, $wantAll = false): array /** * getFiles * * Prim Endpoint: RPC.common.Api.Files.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getFiles(PrimRequestInterface $request, $wantAll = false): array /** * annulFinDocFinDoc * * Prim Endpoint: RPC.common.Api.FinDoc.annulFinDoc * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::annulFinDocFinDoc(PrimRequestInterface $request, $wantAll = false): array /** * setGroups * * Prim Endpoint: RPC.common.Api.Groups.set * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::setGroups(PrimRequestInterface $request, $wantAll = false): array /** * getInterationSystems * * Prim Endpoint: RPC.common.Api.InterationSystems.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getInterationSystems(PrimRequestInterface $request, $wantAll = false): array /** * setInvoice * * Prim Endpoint: RPC.common.Api.Invoice.set * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::setInvoice(PrimRequestInterface $request, $wantAll = false): array /** * setItems * * Prim Endpoint: RPC.common.Api.Items.set * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::setItems(PrimRequestInterface $request, $wantAll = false): array /** * getListOperation * * Prim Endpoint: RPC.common.Api.ListOperation.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getListOperation(PrimRequestInterface $request, $wantAll = false): array /** * setMeasures * * Prim Endpoint: RPC.common.Api.Measures.set * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::setMeasures(PrimRequestInterface $request, $wantAll = false): array /** * getOperations * * Prim Endpoint: RPC.common.Api.Operations.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getOperations(PrimRequestInterface $request, $wantAll = false): array /** * getParams * * Prim Endpoint: RPC.common.Api.Params.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getParams(PrimRequestInterface $request, $wantAll = false): array /** * setPartners * * Prim Endpoint: RPC.common.Api.Partners.set * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::setPartners(PrimRequestInterface $request, $wantAll = false): array /** * getPayTypes * * Prim Endpoint: RPC.common.Api.PayTypes.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getPayTypes(PrimRequestInterface $request, $wantAll = false): array /** * fullAnnulPoPo * * Prim Endpoint: RPC.common.Api.Po.fullAnnulPo * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::fullAnnulPoPo(PrimRequestInterface $request, $wantAll = false): array /** * getPos * * Prim Endpoint: RPC.common.Api.Pos.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getPos(PrimRequestInterface $request, $wantAll = false): array /** * setPrices * * Prim Endpoint: RPC.common.Api.Prices.set * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::setPrices(PrimRequestInterface $request, $wantAll = false): array /** * getPricesLists * * Prim Endpoint: RPC.common.Api.PricesLists.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getPricesLists(PrimRequestInterface $request, $wantAll = false): array /** * setServices * * Prim Endpoint: RPC.common.Api.Services.set * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::setServices(PrimRequestInterface $request, $wantAll = false): array /** * getSoInvoicePdfSo * * Prim Endpoint: RPC.common.Api.So.getSoInvoicePdf * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getSoInvoicePdfSo(PrimRequestInterface $request, $wantAll = false): array /** * getSoOrderTypes * * Prim Endpoint: RPC.common.Api.SoOrderTypes.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getSoOrderTypes(PrimRequestInterface $request, $wantAll = false): array /** * deleteStoreIn * * Prim Endpoint: RPC.common.Api.StoreIn.delete * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::deleteStoreIn(PrimRequestInterface $request, $wantAll = false): array /** * deleteStoreOut * * Prim Endpoint: RPC.common.Api.StoreOut.delete * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::deleteStoreOut(PrimRequestInterface $request, $wantAll = false): array /** * getStores * * Prim Endpoint: RPC.common.Api.Stores.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getStores(PrimRequestInterface $request, $wantAll = false): array /** * getTaxDeals * * Prim Endpoint: RPC.common.Api.TaxDeals.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getTaxDeals(PrimRequestInterface $request, $wantAll = false): array /** * getTaxInstances * * Prim Endpoint: RPC.common.Api.TaxInstances.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getTaxInstances(PrimRequestInterface $request, $wantAll = false): array /** * getVendorTypes * * Prim Endpoint: RPC.common.Api.VendorTypes.get * * * @param \Gdinko\Prim\Interfaces\PrimRequestInterface $request * @param boolean $wantAll * @return array * * @throws \Gdinko\Prim\Exceptions\PrimException * @throws \Gdinko\Prim\Exceptions\PrimValidationException */ Prim::getVendorTypes(PrimRequestInterface $request, $wantAll = false): array
Commands
#get prim api status (use -h to view options) #need to run migrations for this command to store data php artisan prim:api-status
Models
PrimApiStatus PrimLog PrimErrorLog
Events
PrimHookEvent
Interfaces
If you need to make custom PrimRequest you need to implement this interface
PrimRequestInterface
Requests
Implements PrimRequestInterface
PrimRequest PrimNoValidationRequest //no client site data validation PrimCustomRequest //used for GET request, with no data wrapping
Request Example
$pr = new PrimRequest( ['code' => 'Code', 'name' => 'Name'], //request data false, //get all | true / false Prim::getValidationRules('RPC.common.Api.Accounts', 'get'), // auto generate validation rules | or skip this param | or pass custom validation rules true, //by default data will be wrapped in additional [] | true / false )
Listen for Prim Hook Event
- In Prim Dashboard subscribe for Hook and set YOUR API HOOK URL: [your domain]/api/prim/hook?api_token=[laravel:sanctum:token]
//subscribe to PrimHookEvent in EventServiceProvider->boot method //https://laravel.com/docs/9.x/events Event::listen(function (PrimHookEvent $event) { //do something cool with prim payload dd($event->payload); });
Examples
Get All Prim API Methods
use Gdinko\Prim\Facades\Prim; use Gdinko\Prim\Exceptions\PrimException; use Gdinko\Prim\Exceptions\PrimValidationException; try { $methods = Prim::getAllMethods(); dd($methods); } catch (PrimException | PrimValidationException $pe) { echo class_basename($pe) . '<br />'; echo $pe->getCode() . '<br />'; echo $pe->getMessage() . '<br />'; dd($pe->getErrors()); } catch (\Exception $e) { echo class_basename($e) . '<br />'; echo $e->getCode() . '<br />'; echo $e->getMessage() . '<br />'; }
Get All Accounts
*This example usage is valid for all methods
use Gdinko\Prim\Facades\Prim; use Gdinko\Prim\Exceptions\PrimException; use Gdinko\Prim\Exceptions\PrimValidationException; use Gdinko\Prim\Requests\PrimRequest; try { $accounts = Prim::getAccounts( new PrimRequest( [], //empty params true, //get all flag ) ); dd($accounts); } catch (PrimException | PrimValidationException $pe) { echo class_basename($pe) . '<br />'; echo $pe->getCode() . '<br />'; echo $pe->getMessage() . '<br />'; dd($pe->getErrors()); } catch (\Exception $e) { echo class_basename($e) . '<br />'; echo $e->getCode() . '<br />'; echo $e->getMessage() . '<br />'; }
Get All Accounts with no client site validation request and get all prim response, not only result fields
*This example usage is valid for all methods
use Gdinko\Prim\Facades\Prim; use Gdinko\Prim\Exceptions\PrimException; use Gdinko\Prim\Exceptions\PrimValidationException; use Gdinko\Prim\Requests\PrimNoValidationRequest; try { $accounts = Prim::getAccounts( new PrimNoValidationRequest( [], //empty params, no client site validation only prim validation true, //get all flag ), true ); dd($accounts); } catch (PrimException $pe) { echo class_basename($pe) . '<br />'; echo $pe->getCode() . '<br />'; echo $pe->getMessage() . '<br />'; dd($pe->getErrors()); } catch (\Exception $e) { echo class_basename($e) . '<br />'; echo $e->getCode() . '<br />'; echo $e->getMessage() . '<br />'; }
Search for Accounts with autogenerated request validation rules
*This example usage is valid for all methods
use Gdinko\Prim\Facades\Prim; use Gdinko\Prim\Exceptions\PrimException; use Gdinko\Prim\Exceptions\PrimValidationException; use Gdinko\Prim\Requests\PrimRequest; try { $accounts = Prim::getAccounts( new PrimRequest( ['code' => 'CoDe', 'name' => 'NaMe'], //request params false, //dot not return all Prim::getValidationRules('RPC.common.Api.Accounts', 'get') //auto generate validation rules ) ); dd($accounts); } catch (PrimException | PrimValidationException $pe) { echo class_basename($pe) . '<br />'; echo $pe->getCode() . '<br />'; echo $pe->getMessage() . '<br />'; dd($pe->getErrors()); } catch (\Exception $e) { echo class_basename($e) . '<br />'; echo $e->getCode() . '<br />'; echo $e->getMessage() . '<br />'; }
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email dinko359@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
gdinko/prim 适用场景与选型建议
gdinko/prim 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.3k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 10 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「prim」 「gdinko」 「prim laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gdinko/prim 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gdinko/prim 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gdinko/prim 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Common mathematical graph algorithms implemented in PHP
Laravel Speedy API Wrapper
Laravel Econt API Wrapper
pdfMatrix Laravel SDK
Laravel Dynamic Express API Wrapper
Common mathematical graph algorithms
统计信息
- 总下载量: 4.3k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-10-11