jmadsm / gateway-client

用于JMA数据API的PHP客户端。


README

安装包

composer require jmadsm/gateway-client

使用方法

<?php
use JmaDsm\GatewayClient\Client;
use JmaDsm\GatewayClient\ApiObjects\Product;
use JmaDsm\GatewayClient\ApiObjects\Category;

// Create singleton instance of the client
Client::getInstance( // get the config from JMA
     $config['base_url'],
     $config['access_token'],
     $config['tenant_token']
 );

$product    = Product::get('product_id');
$categories = Category::all();

while ($category = $categories->next()) { // The categories object will recursively fetch all categories in chuncks.
    echo $category->name;
}

示例

有关如何使用不同对象类型的示例,请参阅示例目录。

如何在部署前测试您的更改?

进入示例文件夹,从示例文件创建config.php文件。在您将必要数据添加到config.php文件后,您可以通过在终端中运行例如"php examples/products.php"来测试方法。这需要您的机器已设置并配置了PHP版本8以上。

新PHPUnit功能用于测试

php vendor/bin/phpunit Tests/ClientTest.php