Refactor request handling in FederationServer to streamline method matching and improve error responses
Some checks are pending
CI / check-phpdoc (push) Waiting to run
CI / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / generate-phpdoc (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / release-documentation (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
Some checks are pending
CI / check-phpdoc (push) Waiting to run
CI / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / generate-phpdoc (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / release-documentation (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
This commit is contained in:
parent
319aa80159
commit
51dfc1e9a5
1 changed files with 6 additions and 49 deletions
|
@ -2,22 +2,10 @@
|
||||||
|
|
||||||
namespace FederationServer;
|
namespace FederationServer;
|
||||||
|
|
||||||
use FederationServer\Classes\Configuration;
|
|
||||||
use FederationServer\Classes\Enums\AuditLogType;
|
|
||||||
use FederationServer\Classes\Enums\Method;
|
use FederationServer\Classes\Enums\Method;
|
||||||
use FederationServer\Classes\FileUploadHandler;
|
|
||||||
use FederationServer\Classes\Logger;
|
|
||||||
use FederationServer\Classes\Managers\AuditLogManager;
|
|
||||||
use FederationServer\Classes\Managers\FileAttachmentManager;
|
|
||||||
use FederationServer\Classes\Managers\OperatorManager;
|
|
||||||
use FederationServer\Classes\RequestHandler;
|
use FederationServer\Classes\RequestHandler;
|
||||||
use FederationServer\Exceptions\DatabaseOperationException;
|
|
||||||
use FederationServer\Exceptions\RequestException;
|
use FederationServer\Exceptions\RequestException;
|
||||||
use FederationServer\Methods\CreateOperator;
|
|
||||||
use FederationServer\Methods\DownloadAttachment;
|
|
||||||
use FederationServer\Methods\UploadAttachment;
|
|
||||||
use FederationServer\Objects\OperatorRecord;
|
use FederationServer\Objects\OperatorRecord;
|
||||||
use Throwable;
|
|
||||||
|
|
||||||
class FederationServer extends RequestHandler
|
class FederationServer extends RequestHandler
|
||||||
{
|
{
|
||||||
|
@ -36,30 +24,15 @@
|
||||||
parent::handleRequest();
|
parent::handleRequest();
|
||||||
|
|
||||||
// Execute the request method
|
// Execute the request method
|
||||||
Method::matchHandle(self::getRequestMethod(), self::getPath())->handleRequest();
|
|
||||||
|
|
||||||
switch (true)
|
$requestMethod = Method::matchHandle(self::getRequestMethod(), self::getPath());
|
||||||
|
if($requestMethod === null)
|
||||||
{
|
{
|
||||||
case self::getRequestMethod() === 'POST' && self::getPath() === '/':
|
self::errorResponse('Invalid request method or path.', 400);
|
||||||
self::errorResponse('Method Not Allowed', 405);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case preg_match('#^/attachment/([a-fA-F0-9\-]{36,})$#', self::getPath()):
|
|
||||||
DownloadAttachment::handleRequest();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case self::getRequestMethod() === 'POST' && self::getPath() === '/createOperator':
|
|
||||||
CreateOperator::handleRequest();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case (self::getRequestMethod() === 'POST' | self::getRequestMethod() === 'PUT') && self::getPath() === '/upload':
|
|
||||||
UploadAttachment::handleRequest();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
self::errorResponse('Method Not Found', 405);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle the request based on the matched method.
|
||||||
|
$requestMethod->handleRequest();
|
||||||
}
|
}
|
||||||
catch (RequestException $e)
|
catch (RequestException $e)
|
||||||
{
|
{
|
||||||
|
@ -67,22 +40,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle the root POST request.
|
|
||||||
*
|
|
||||||
* This method is a placeholder for handling POST requests to the root path.
|
|
||||||
* It can be extended to implement specific functionality as needed.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private static function handlePost(): void
|
|
||||||
{
|
|
||||||
// Placeholder for handling POST requests to the root path.
|
|
||||||
// This can be extended to implement specific functionality as needed.
|
|
||||||
self::successResponse(['message' => 'Root POST request handled successfully.']);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a parameter from the request, checking POST, GET, and decoded JSON content.
|
* Get a parameter from the request, checking POST, GET, and decoded JSON content.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue