klevu/php-sdk
Composer 安装命令:
composer require klevu/php-sdk
包简介
Klevu SDK for PHP
README 文档
README
The Klevu PHP-SDK is a small package designed to simplify communicating with Klevu API services.
Getting Started
- Create an account with Klevu.
Free trial, with full access to all features is available. - Retrieve your JS API Key and REST AUTH Key from Store Settings > Store Info in your account.
- Install the SDK in your application using composer.
composer require klevu/php-sdk
- Start building!
There are some quick-start examples below, as well as detailed guides in our developer documentation.
System Requirements
To use this library, you must be running PHP 8.1 compiled with the libxml and simplexml extensions.
See the PHP docs for more information.
You will also require a PSR-18 compatible HTTP client, such as guzzlehttp/guzzle,
which provides psr/http-client-implementation support.
A list of compatible libraries can be found on Packagist.
We also recommend a PSR-3 compatible logger library, such as monolog/monolog.
This will allow the SDK to write activity it performs to a location of your choice.
Quick Start Guide
Account Credentials
The AccountCredentials object is required by all services connecting with Klevu.
You will need both your JS API Key (in the format klevu-xxxxxxx) and your REST AUTH Key from your Klevu account.
When saving and accessing these credentials within your application, please treat the REST AUTH Key in the same manner as any other sensitive information, such as passwords.
If you need to change your REST AUTH Key, please contact our support team.
Create a new Klevu\PhpSDK\Model\AccountCredentials object. Note, account credentials objects are immutable.
<?php declare(strict_types=1); // Include the composer autoloader - you may need to change the directory path require_once 'vendor/autoload.php'; use Klevu\PhpSDK\Model\AccountCredentials; $accountCredentials = new AccountCredentials( jsApiKey: '[Your JS API Key]', restAuthKey: '[Your REST AUTH KEY]', );
Retrieving Account Details
You can find a more complete example of retrieving account information in the examples section
The AccountLookupService lets you retrieve details about your Klevu account, including hostnames required to push and pull data to other services.
<?php declare(strict_types=1); // Include the composer autoloader - you may need to change the directory path require_once 'vendor/autoload.php'; use Klevu\PhpSDK\Model\AccountCredentials; use Klevu\PhpSDK\Service\Account\AccountLookupService; $accountLookupService = new AccountLookupService(); $accountCredentials = new AccountCredentials( jsApiKey: '[Your JS API Key]', restAuthKey: '[Your REST AUTH KEY]', ); $account = $accountLookupService->execute($accountCredentials); var_export($account);
Which will return an object as follows.
Klevu\PhpSDK\Model\Account::__set_state(array(
'jsApiKey' => 'klevu-1234567890',
'restAuthKey' => 'ABCDE1234567890',
'platform' => 'custom',
'isActive' => true,
'companyName' => 'Klevu',
'email' => 'contact@klevu.com',
'indexingUrl' => 'indexing-api.ksearchnet.com',
'searchUrl' => 'cs.ksearchnet.com',
'smartCategoryMerchandisingUrl' => 'cn.ksearchnet.com',
'analyticsUrl' => 'stats.klevu.com',
'jsUrl' => 'js.klevu.com',
'tiersUrl' => 'tiers.klevu.com',
'accountFeatures' => NULL,
))
Each property listed is private and accessed through getters, as follows
$account->getJsApiKey();
Note, in the example above we instantiate the service implementation rather than the interface.
If you are using dependency injection, we recommend configuring theKlevu\PhpSDK\Api\Interface\Service\Account\AccountLookupServiceinterface toKlevu\PhpSDK\Service\Account\AccountLookupService, along with any constructor arguments.
For example:
$accountLookupService = $container->get(\Klevu\PhpSDK\Api\Service\Account\AccountLookupServiceInterface::class);
Retrieving Account Features
In the example above, the returned model's accountFeatures property is empty. In order to load your account's
enabled features, you will need to invoke the
AccountFeaturesService, as shown.
<?php declare(strict_types=1); // Include the composer autoloader - you may need to change the directory path require_once 'vendor/autoload.php'; use Klevu\PhpSDK\Model\AccountCredentials; use Klevu\PhpSDK\Service\Account\AccountFeaturesService; $accountFeaturesService = new AccountFeaturesService(); $accountCredentials = new AccountCredentials( jsApiKey: '[Your JS API Key]', restAuthKey: '[Your REST AUTH KEY]', ); $accountFeatures = $accountFeaturesService->execute($accountCredentials); var_export($account);
Which will return an immutable object as follows.
Klevu\PhpSDK\Model\Account\AccountFeatures::__set_state(array(
'smartCategoryMerchandising' => true,
'smartRecommendations' => true,
'preserveLayout' => true,
))
Each property is public and can be accessed directly, but not modified.
You can also attach this to your loaded account model by setting the accountFeatures property. This is not required
but you may find it useful to have all data in a single model within your application.
$account->setAccountFeatures($accountFeatures); var_export($account);
Klevu\PhpSDK\Model\Account::__set_state(array(
'jsApiKey' => 'klevu-1234567890',
'restAuthKey' => 'ABCDE1234567890',
'platform' => 'custom',
'isActive' => true,
'companyName' => 'Klevu',
'email' => 'contact@klevu.com',
'indexingUrl' => 'indexing-api.ksearchnet.com',
'searchUrl' => 'cs.ksearchnet.com',
'smartCategoryMerchandisingUrl' => 'cn.ksearchnet.com',
'analyticsUrl' => 'stats.klevu.com',
'jsUrl' => 'js.klevu.com',
'tiersUrl' => 'tiers.klevu.com',
'accountFeatures' => Klevu\PhpSDK\Model\Account\AccountFeatures::__set_state(array(
'smartCategoryMerchandising' => true,
'smartRecommendations' => true,
'preserveLayout' => true,
)),
))
Note: as with the previous example, we instantiated the implementation rather than the interface in our example. Again, we recommend mapping with dependency injection if your application supports this.
klevu/php-sdk 适用场景与选型建议
klevu/php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.38k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 09 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sdk」 「klevu」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 klevu/php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 klevu/php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 klevu/php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Klevu pipeline-based conversion library
Klevu SDK integration with pipelines library
PHP SDK for the Enconvert file conversion API
支付宝开放平台v3协议文档,支持最新版PHP8+
Merchant-side PHP SDK for YoPay Pay Open API.
SDK oficial da API AurePay para PHP (tipado via OpenAPI)
统计信息
- 总下载量: 20.38k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 7
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-30