Source
<?php
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/**
* This class should be used to call API services locally using the CApiService classes.
*/
class CLocalApiClient extends CApiClient {
/**
* Factory for creating API services.
*
* @var CRegistryFactory
*/
protected $serviceFactory;
/**
* Whether debug mode is enabled.
*
* @var bool
*/
protected $debug = false;
/**
* Set service factory.
*
* @param CRegistryFactory $factory
*/
public function setServiceFactory(CRegistryFactory $factory) {
$this->serviceFactory = $factory;
}
/**
* Call the given API service method and return the response.
*
* @param string $requestApi API name.
* @param string $requestMethod API method.
* @param array $params API parameters.
* @param array $auth
* @param int $auth['type'] CJsonRpc::AUTH_TYPE_PARAM, CJsonRpc::AUTH_TYPE_HEADER, CJsonRpc::AUTH_TYPE_COOKIE
* @param string $auth['auth'] Authentication token.
*
* @return CApiClientResponse
*/
public function callMethod(string $requestApi, string $requestMethod, array $params, array $auth) {
global $DB;
$api = strtolower($requestApi);
$method = strtolower($requestMethod);
$response = new CApiClientResponse();