canaltp/tyr-component

PHP 库,用于向 Tyr API 发送 curl 调用。

1.3.2 2017-02-20 14:55 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:42:07 UTC


README

PHP 库,用于向 Tyr API 发送 curl 调用。

从版本 1.2 开始支持 Guzzle3 和 Guzzle5。

Composer

通过 composer 安装

{
    "require": {
        "canaltp/tyr-component": "~1.2"
    }
}

使用方法

将 TyrService 实例化为普通的 PHP 对象

$tyrUrl = 'http://tyr.dev.canaltp.fr/v0/';
$endPointId = 2;

// Instanciating api
$tyrApi = new CanalTP\TyrComponent\TyrService($tyrUrl, $endPointId); // For Guzzle5
$tyrApi = new CanalTP\TyrComponent\Guzzle3\TyrService($tyrUrl, $endPointId); // For Guzzle3

// Creating request
$user = $tyrApi->createUser('email', 'login');

// Get last Guzzle response instance (usefull to get status code...)
$response = $tyrApi->getLastResponse();
$statusCode = $response->getStatusCode();

查看完整的 Tyr 类

测试

模拟 Guzzle 客户端

$tyrUrl = 'http://tyr.dev.canaltp.fr/v0/';
$endPointId = 2;

$tyrApi = new CanalTP\TyrComponent\TyrService($tyrUrl, $endPointId); // For Guzzle5
$tyrApi = new CanalTP\TyrComponent\Guzzle3\TyrService($tyrUrl, $endPointId); // For Guzzle3

// Creating GuzzleHttp\Client mock...

$tyrApi->setClient($mockedClient);

许可证

该项目遵循GPL-3.0 许可证