Add authentication configuration and allowed methods logic

This commit is contained in:
netkas 2025-01-07 15:25:32 -05:00
parent cabf1f35a8
commit 70c0fb2e54
4 changed files with 349 additions and 65 deletions

View file

@ -0,0 +1,38 @@
<?php
namespace Socialbox\Classes\StandardMethods;
use Socialbox\Abstracts\Method;
use Socialbox\Enums\StandardError;
use Socialbox\Enums\StandardMethods;
use Socialbox\Exceptions\DatabaseOperationException;
use Socialbox\Exceptions\StandardException;
use Socialbox\Interfaces\SerializableInterface;
use Socialbox\Objects\ClientRequest;
use Socialbox\Objects\RpcRequest;
class GetAllowedMethods extends Method
{
/**
* @inheritDoc
*/
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
{
$allowedMethods = [];
try
{
foreach(StandardMethods::getAllowedMethods($request) as $method)
{
$allowedMethods[] = $method->value;
}
}
catch(DatabaseOperationException $e)
{
throw new StandardException('Failed to retrieve allowed methods due to an internal exception', StandardError::INTERNAL_SERVER_ERROR, $e);
}
return $rpcRequest->produceResponse($allowedMethods);
}
}