zendserverwebapi/zendserverwebapi

提供对Zend Server API的便捷访问

1.3 2014-02-26 16:52 UTC

README

简化Zend Server API使用的ZF2模块

Zend Framework 2 API

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

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

然后发送请求并像这样检索响应

$apiResponse = $apiManager->apiMethodName();

其中ApiMethodName是API方法:getNotifications、cacheClear等。请参阅Zend Server 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可以通过数组传递给ApiManager

$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',
)),