sroze/hipache-client

一个 Hipache 客户端的 PHP 实现

1.0.0 2015-05-08 13:59 UTC

This package is auto-updated.

Last update: 2024-08-29 04:03:29 UTC


README

Scrutinizer Code Quality

这个库是一个 Hipache PHP 客户端。

安装

使用 Composer 将此库作为依赖项安装

composer require sroze/hipache-client

用法

用法非常简单,可以通过 Client 对象端点完成。

创建客户端

Client 类应与适配器一起创建,因为 Hipchat 支持多个适配器(称为驱动程序)。有关如何实例化适配器的信息,请参阅适配器部分。

use Hipache\Client;

$client = new Client($adapter);

列出所有前端

只需调用 getFrontendCollection 方法即可获得可遍历的前端集合

$frontendCollection = $client->getFrontendCollection();

foreach ($frontendCollection as $frontend) {
    echo $frontend->getHostname();
}

创建前端

客户端上的 createFrontend 方法允许您创建前端

use Hipache\Frontend\Frontend;
use Hipache\Frontend\Exception\FrontendAlreadyExists;

try {
    $frontend = $client->createFrontend(new Frontend('www.example.com'));
} catch (FrontendAlreadyExists $e) {
    // Given frontend can't be created since it already exists...
}

根据域名获取前端

有一个 getFrontend 方法,可以根据名称返回一个 Frontend 对象。

use Hipache\Frontend\Exception\FrontendNotFound;

try {
    $frontend = $client->getFrontend('www.example.com');
} catch (FrontendNotFound $e) {
    // Frontend was not found...
}

更新前端的后端

当您使用 Client 类获取一个前端时,您有一个 WritableFrontend 实例。这意味着您只需调用 addremove 方法之一即可分别添加或从其中删除后端。

以下是如何向给定前端添加 2 个后端的示例

use Hipache\Backend\Backend;

$frontend = $client->getFrontend('sroze.io');
$frontend->add(new Backend('http://1.2.3.4:8000'));
$frontend->add(new Backend('http://1.2.3.4:8001'));

如果您想删除后端,只需添加 remove 方法

$frontend = $client->getFrontend('sroze.io');
$frontend->remove(new Backend('http://1.2.3.4:8000'));

适配器

目前只支持 Redis 适配器(推荐适配器)。

Redis 适配器

需要使用配置好的 Predis 客户端来构造 RedisAdapter 类,就这么多。

以下是如何创建 Redis 适配器实例的示例

use Predis\Client as RedisClient;
use Hipache\Adapter\RedisAdapter;

$adapter = new RedisAdapter(new RedisClient('tcp://172.17.0.18:6379'));