l3 / client-api-glpi-bundle
为简单使用 GLPI 的 web 服务提供 Symfony 2.7 的捆绑包。
1.0.0
2018-01-26 10:39 UTC
Requires
- php: >=5.3.9
- symfony/symfony: ~2,>=2.7
This package is auto-updated.
Last update: 2024-09-10 16:07:11 UTC
README
为简单使用 GLPI 的 web 服务提供 Symfony 2.7 的捆绑包
安装
使用此命令
composer require "l3/client-api-glpi-bundle"
并在 AppKernel.php 文件中添加捆绑包。
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new L3\Bundle\ClientApiGlpiBundle\L3ClientApiGlpiBundle(),
);
// ...
}
// ...
}
配置
在您的应用程序中,您应该添加一个服务以使用此捆绑包的功能
为了使用 XML-RPC 协议
parameters:
# Lien vers le script 'xmlrpc.php' du plugin 'Webservices' :
webservice_xmlrpc_url: https://assistance.univ-lille3.fr/plugins/webservices/xmlrpc.php
services:
# Client pour le plugin 'Webservices' de GLPI (protocole XML-RPC) :
webservice_xmlrpc_client:
class: L3\Bundle\ClientApiGlpiBundle\Services\PluginWebservicesXmlRpcClient
arguments: ["%webservice_xmlrpc_url%"]
为了使用 REST 协议
parameters:
# Lien vers le script 'rest.php' du plugin 'Webservices' :
webservice_rest_url: https://assistance.univ-lille3.fr/plugins/webservices/rest.php
services:
# Client pour le plugin 'Webservices' de GLPI (protocole REST) :
webservice_rest_client:
class: L3\Bundle\ClientApiGlpiBundle\Services\PluginWebservicesRestClient
arguments: ["%webservice_rest_url%"]
使用方法
/* initialisation du service */
$api = $this->get('webservice_rest_client');
/* login sur l'api (récupération d'une session) */
$session = $api->login('test_login', 'test_password');
/* execution d'une requête non authentifiée et sans arguments */
$test = $api->call('glpi.test', null);
/* execution d'une requête authentifiée sans arguments */
$mes_informations = $api->call('glpi.getMyInfo', null, $session);
/* execution d'une requête authentifiée avec arguments */
$tickets = $api->call('glpi.listTickets', [
'limit' => 10,
'status' => 'all',
'startdate' => '2016-01-01',
'enddate' => '2016-02-01'
], $session);
/* logout de l'api (destruction de la session) */
$api->logout($session);