Add new classes and methods for session management

This commit is contained in:
netkas 2024-09-13 13:52:38 -04:00
parent b9c84aeb27
commit 764ec51fa4
12 changed files with 1026 additions and 28 deletions

View file

@ -1,8 +1,54 @@
<?php
namespace socialbox;
namespace Socialbox;
use Socialbox\Classes\RpcHandler;
use Socialbox\Enums\StandardError;
use Socialbox\Enums\StandardMethods;
use Socialbox\Exceptions\RpcException;
class Socialbox
{
public static function handleRpc(): void
{
try
{
$clientRequest = RpcHandler::getClientRequest();
}
catch(RpcException $e)
{
http_response_code($e->getCode());
print($e->getMessage());
return;
}
$results = [];
foreach($clientRequest->getRequests() as $rpcRequest)
{
$method = StandardMethods::tryFrom($rpcRequest->getMethod());
if($method === false)
{
$response = $rpcRequest->produceError(StandardError::RPC_METHOD_NOT_FOUND, 'The requested method does not exist');;
if($response !== null)
{
$results[] = $response;
}
}
$response = $method->execute($clientRequest, $rpcRequest);
if($response !== null)
{
$results[] = $response;
}
}
if(count($results) > 0)
{
print(json_encode($results));
return;
}
http_response_code(204);
}
}