Enhance session handling and introduce session flags
This commit is contained in:
parent
6c8cbfddec
commit
790262db08
6 changed files with 251 additions and 81 deletions
40
src/Socialbox/Classes/StandardMethods/GetSession.php
Normal file
40
src/Socialbox/Classes/StandardMethods/GetSession.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Socialbox\Classes\StandardMethods;
|
||||
|
||||
use Socialbox\Abstracts\Method;
|
||||
use Socialbox\Enums\StandardError;
|
||||
use Socialbox\Exceptions\DatabaseOperationException;
|
||||
use Socialbox\Exceptions\StandardException;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Managers\RegisteredPeerManager;
|
||||
use Socialbox\Managers\SessionManager;
|
||||
use Socialbox\Objects\ClientRequest;
|
||||
use Socialbox\Objects\RpcRequest;
|
||||
|
||||
class GetSession extends Method
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||
{
|
||||
if($request->getSessionUuid() === null)
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::SESSION_REQUIRED);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Get the session
|
||||
$session = SessionManager::getSession($request->getSessionUuid());
|
||||
}
|
||||
catch(DatabaseOperationException $e)
|
||||
{
|
||||
throw new StandardException("There was an unexpected error while trying to retrieve the session", StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -192,4 +192,26 @@ class Utilities
|
|||
{
|
||||
return preg_replace('/[^a-zA-Z0-9-_]/', '', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array into a serialized string by joining the elements with a comma.
|
||||
*
|
||||
* @param array $list An array of elements that need to be converted to a comma-separated string.
|
||||
* @return string A string representation of the array elements, joined by commas.
|
||||
*/
|
||||
public static function serializeList(array $list): string
|
||||
{
|
||||
return implode(',', $list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a serialized string into an array by splitting the string at each comma.
|
||||
*
|
||||
* @param string $list A comma-separated string that needs to be converted to an array.
|
||||
* @return array An array of string values obtained by splitting the input string.
|
||||
*/
|
||||
public static function unserializeList(string $list): array
|
||||
{
|
||||
return explode(',', $list);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue