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/>.
**/
namespace SCIM;
use CJsonRpc;
use APIException;
use CApiClientResponse;
use CHttpRequest;
use SCIM\clients\ScimApiClient;
class API {
/**
* Executes received request.
*
* @param ScimApiClient $client API client.
* @param CHttpRequest $request Request received.
*
* @return HttpResponse
*/
public function execute(ScimApiClient $client, CHttpRequest $request): HttpResponse {
$response = new HttpResponse();
$endpoint = strtolower($request->getPathInfoSegment(0));
$method = strtolower($request->method());
$input = $this->getRequestData($request);
$response->setRequestDetails($endpoint, $method, $input);
$response->setResponse(
$client->callMethod($endpoint, $method, $input, [
'type' => CJsonRpc::AUTH_TYPE_HEADER,
'auth' => $request->getAuthBearerValue()
])
);
return $response;
}
/**
* Returns SCIM HTTP request data in array form for SCIM API.
*
* @param CHttpRequest $request
*
* @return array
* @throws Exception
*/
public function getRequestData(CHttpRequest $request): array {
$data = (array) json_decode($request->body(), true);
$filter = $request->getUrlArgument('filter', '');
if ($request->getPathInfoSegment(1) !== '') {