mvenghaus/saloon-magento2-connector

Magento 2 的 Saloon 连接器

1.0.0 2024-05-31 04:40 UTC

This package is auto-updated.

Last update: 2024-08-31 00:52:56 UTC


README

Saloon - 具有令牌处理的 Magento 2 连接器,允许您轻松开始构建自己的请求。仅在两步验证(2FA)禁用时才有效。

安装

使用 composer 安装此包

composer require mvenghaus/saloon-magento2-connector

用法

基本结构

$configuration = new Configuration(...);
$connector = new Connector($configuration);

$response = $connector->send(new Your_Request());

配置 - 结构

class Configuration
{
    public function __construct(
        public string $endpoint, // https://www.your-domain.com/rest/V1/
        public string $username,
        public string $password,
        public int $tokenLifetime = 0, // admin defined token lifetime in seconds 
        public ?string $authenticator = null, // saloon authenticator (serialized)
        public ?Closure $authenticatorUpdateCallback = null, // callback to save authenticator if changed
        public ?Closure $debugCallback = null // callback for debugging
    ) {
    }
}

配置 - 示例

$authenticator = load_from_your_cache();

$configuration = new Configuration(
    'https://www.your-domain.com/rest/V1/',
    'USERNAME',
    'PASSWORD',
    3600,
    $authenticator,
    function (string $authenticator) {
        save_to_your_cache($authenticator);
    },
    function (PendingRequest $pendingRequest, RequestInterface $psrRequest) {
        echo $pendingRequest->getUrl() . PHP_EOL;
    }
);