From fb6e98bb5c595eab3eeb85667aacff030ea7be82 Mon Sep 17 00:00:00 2001 From: netkas Date: Fri, 13 Sep 2024 13:52:17 -0400 Subject: [PATCH] Add Method abstract class with session handling --- src/Socialbox/Abstracts/Method.php | 52 +++++++++++++++++++ .../Interfaces/SerializableInterface.php | 14 ++--- 2 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 src/Socialbox/Abstracts/Method.php diff --git a/src/Socialbox/Abstracts/Method.php b/src/Socialbox/Abstracts/Method.php new file mode 100644 index 0000000..3987ed1 --- /dev/null +++ b/src/Socialbox/Abstracts/Method.php @@ -0,0 +1,52 @@ +getSessionUuid() === null) + { + return null; + } + + try + { + if(!SessionManager::sessionExists($request->getSessionUuid())) + { + throw new StandardException(sprintf("The requested session %s was not found", $request->getSessionUuid()), StandardError::SESSION_NOT_FOUND); + } + + return SessionManager::getSession($request->getSessionUuid()); + } + catch(DatabaseOperationException $e) + { + throw new StandardException("There was an error while retrieving the session from the server", StandardError::INTERNAL_SERVER_ERROR); + } + } +} \ No newline at end of file diff --git a/src/Socialbox/Interfaces/SerializableInterface.php b/src/Socialbox/Interfaces/SerializableInterface.php index 936f9fa..aec71dd 100644 --- a/src/Socialbox/Interfaces/SerializableInterface.php +++ b/src/Socialbox/Interfaces/SerializableInterface.php @@ -4,17 +4,17 @@ namespace Socialbox\Interfaces; interface SerializableInterface { - /** - * Serializes the object to an array. - * - * @return array - */ - public function toArray(): array; - /** * Constructs the object from an array of data. * * @param array $data The data to construct the object from. */ public static function fromArray(array $data): object; + + /** + * Serializes the object to an array. + * + * @return array + */ + public function toArray(): array; } \ No newline at end of file