Files

80 lines
2.9 KiB
PHP
Executable File

<?php
namespace app\core;
Class DVC
{
public static string $nameOfResponsePackage = "response_package";
public static string $successName = "Success";
public static string $genericExceptionName = "GenericErrorException";
public static string $invalidTokenName = "InvalidTokenException";
public static string $invalidRequestName = "InvalidRequestException";
public static string $invalidBodyName = "InvalidBodyException";
public static string $alreadyExistsName = "AlreadyExistsException";
public static string $userAlreadyExistsName = "userAlreadyExistsException";
public static string $userNotExistingName = "userNotExistingException";
public static string $fieldNotExistingName = "FieldNotExistingException";
public static string $returnCode = "returnCode";
public static string $returnMessage = "returnMessage";
public static int $successReturnCode = 460;
public static function getArrayResponse(string $name): array
{
return match ($name){
DVC::$successName => [
DVC::$returnCode => 460,
DVC::$returnMessage => "Operation done successfully"
],
DVC::$genericExceptionName => [
DVC::$returnCode => 461,
DVC::$returnMessage => "Internal Server Error"
],
DVC::$invalidTokenName => [
DVC::$returnCode => 462,
DVC::$returnMessage => "Unauthorized access"
],
DVC::$invalidRequestName => [
DVC::$returnCode => 463,
DVC::$returnMessage => "Service doesn't provide this type of request"
],
DVC::$invalidBodyName => [
DVC::$returnCode => 464,
DVC::$returnMessage => "Not valid parameters sent"
],
DVC::$alreadyExistsName => [
DVC::$returnCode => 465,
DVC::$returnMessage => "Field already existing"
],
DVC::$fieldNotExistingName => [
DVC::$returnCode => 466,
DVC::$returnMessage => "Field not existing anymore"
],
DVC::$userAlreadyExistsName => [
DVC::$returnCode => 467,
DVC::$returnMessage => "User already exists with this email"
],
DVC::$userNotExistingName => [
DVC::$returnCode => 468,
DVC::$returnMessage => "User account doesn't exists"
]
};
}
public static function getHttpCodeWithCode(int $code): int
{
return match ($code){
460 => 200,
461 => 500,
462 => 401,
463 => 405,
464 => 400,
465, 466 => 204,
467 => 409,
468 => 404,
default => 100
};
}
}