Add new Enums to enhance error handling and session management
This commit is contained in:
parent
2cf1a55e8f
commit
178e16627f
7 changed files with 197 additions and 0 deletions
26
src/Socialbox/Enums/StandardMethods.php
Normal file
26
src/Socialbox/Enums/StandardMethods.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Socialbox\Enums;
|
||||
|
||||
use Socialbox\Classes\StandardMethods\CreateSession;
|
||||
use Socialbox\Classes\StandardMethods\Ping;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Objects\ClientRequest;
|
||||
use Socialbox\Objects\RpcRequest;
|
||||
|
||||
enum StandardMethods : string
|
||||
{
|
||||
case PING = 'ping';
|
||||
case CREATE_SESSION = 'create_session';
|
||||
|
||||
public function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||
{
|
||||
return match ($this)
|
||||
{
|
||||
self::PING => Ping::execute($request, $rpcRequest),
|
||||
self::CREATE_SESSION => CreateSession::execute($request, $rpcRequest),
|
||||
|
||||
default => $rpcRequest->produceError(StandardError::RPC_METHOD_NOT_FOUND, sprintf('The method %s is not handled by the server', $this->value)),
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue