api de gestion de ticket, basé sur php-crud-api. Le but est de décorrélé les outils de gestion des données, afin
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ErrorCode.php 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Tqdev\PhpCrudApi\Record;
  3. use Tqdev\PhpCrudApi\ResponseFactory;
  4. class ErrorCode
  5. {
  6. private $code;
  7. private $message;
  8. private $status;
  9. public const ERROR_NOT_FOUND = 9999;
  10. public const ROUTE_NOT_FOUND = 1000;
  11. public const TABLE_NOT_FOUND = 1001;
  12. public const ARGUMENT_COUNT_MISMATCH = 1002;
  13. public const RECORD_NOT_FOUND = 1003;
  14. public const ORIGIN_FORBIDDEN = 1004;
  15. public const COLUMN_NOT_FOUND = 1005;
  16. public const TABLE_ALREADY_EXISTS = 1006;
  17. public const COLUMN_ALREADY_EXISTS = 1007;
  18. public const HTTP_MESSAGE_NOT_READABLE = 1008;
  19. public const DUPLICATE_KEY_EXCEPTION = 1009;
  20. public const DATA_INTEGRITY_VIOLATION = 1010;
  21. public const AUTHENTICATION_REQUIRED = 1011;
  22. public const AUTHENTICATION_FAILED = 1012;
  23. public const INPUT_VALIDATION_FAILED = 1013;
  24. public const OPERATION_FORBIDDEN = 1014;
  25. public const OPERATION_NOT_SUPPORTED = 1015;
  26. public const TEMPORARY_OR_PERMANENTLY_BLOCKED = 1016;
  27. public const BAD_OR_MISSING_XSRF_TOKEN = 1017;
  28. public const ONLY_AJAX_REQUESTS_ALLOWED = 1018;
  29. public const PAGINATION_FORBIDDEN = 1019;
  30. private $values = [
  31. 9999 => ["%s", ResponseFactory::INTERNAL_SERVER_ERROR],
  32. 1000 => ["Route '%s' not found", ResponseFactory::NOT_FOUND],
  33. 1001 => ["Table '%s' not found", ResponseFactory::NOT_FOUND],
  34. 1002 => ["Argument count mismatch in '%s'", ResponseFactory::UNPROCESSABLE_ENTITY],
  35. 1003 => ["Record '%s' not found", ResponseFactory::NOT_FOUND],
  36. 1004 => ["Origin '%s' is forbidden", ResponseFactory::FORBIDDEN],
  37. 1005 => ["Column '%s' not found", ResponseFactory::NOT_FOUND],
  38. 1006 => ["Table '%s' already exists", ResponseFactory::CONFLICT],
  39. 1007 => ["Column '%s' already exists", ResponseFactory::CONFLICT],
  40. 1008 => ["Cannot read HTTP message", ResponseFactory::UNPROCESSABLE_ENTITY],
  41. 1009 => ["Duplicate key exception", ResponseFactory::CONFLICT],
  42. 1010 => ["Data integrity violation", ResponseFactory::CONFLICT],
  43. 1011 => ["Authentication required", ResponseFactory::UNAUTHORIZED],
  44. 1012 => ["Authentication failed for '%s'", ResponseFactory::FORBIDDEN],
  45. 1013 => ["Input validation failed for '%s'", ResponseFactory::UNPROCESSABLE_ENTITY],
  46. 1014 => ["Operation forbidden", ResponseFactory::FORBIDDEN],
  47. 1015 => ["Operation '%s' not supported", ResponseFactory::METHOD_NOT_ALLOWED],
  48. 1016 => ["Temporary or permanently blocked", ResponseFactory::FORBIDDEN],
  49. 1017 => ["Bad or missing XSRF token", ResponseFactory::FORBIDDEN],
  50. 1018 => ["Only AJAX requests allowed for '%s'", ResponseFactory::FORBIDDEN],
  51. 1019 => ["Pagination forbidden", ResponseFactory::FORBIDDEN],
  52. ];
  53. public function __construct(int $code)
  54. {
  55. if (!isset($this->values[$code])) {
  56. $code = 9999;
  57. }
  58. $this->code = $code;
  59. $this->message = $this->values[$code][0];
  60. $this->status = $this->values[$code][1];
  61. }
  62. public function getCode(): int
  63. {
  64. return $this->code;
  65. }
  66. public function getMessage(string $argument): string
  67. {
  68. return sprintf($this->message, $argument);
  69. }
  70. public function getStatus(): int
  71. {
  72. return $this->status;
  73. }
  74. }