zenddevops/webapi

提供对 Zend 服务器 API 的便捷访问

1.3 2014-02-26 16:52 UTC

README

简化 Zend 服务器 API 使用的 ZF2 模块

Zend Framework 2 API

要使用 Zend 服务器 API,请从服务定位器调用 APIManager

$apiManager = $serviceLocator->get('zend_server_api');

然后发送请求并按如下方式获取响应

$apiResponse = $apiManager->apiMethodName();

其中 ApiMethodName 是 API 方法:getNotifications、cacheClear 等......见 Zend 服务器 Web API 文档。$apiResponse 将是 ApiResponse 实例,可以将其用作 SimpleXMLElement 以获取 XML 数据。例如,clusterGetServerStatus 方法将返回一个响应,您可以通过如下方式访问数据

$nodeCount = $apiResponse->responseData->serverList->count(); //To know the number a nodes in the cluster
$serverStatus = $apiResponse->responseData->serverList->serverInfo[0]->status // To know the status of the first node

API 请求参数 POST 或 GET 可以通过数组传递给 ApiManger

$response = $apiManager->auditGetList(array(
        'limit' => 5,
        'order' => 'creation_time',
        'direction' => 'DESC'
    ));

设置

您可以在 zendserverwebapi.conf.php 文件中的 'zsapi' 键下设置您环境的默认配置

'zsapi' => array (
    //Configuratin of the HTTP client that will connect to the Zend Server
    'client' => array (
        'adapter' => 'Zend\Http\Client\Adapter\Curl',
    ),
    // Target - the Zend Server you want to reach through API
    'target' => new ArrayObject(array (
        'zsurl' => 'https://:10081', //
        'zskey' => '<SECRET-NAME>',
        'zssecret' => '<SECRET-HASH>',
        'zsversion' => '6.1',
)),