age collapsing has-emoji"> d01d7cf85d first commit 4 年之前 link-template.php d01d7cf85d first commit 4 年之前 load.php d01d7cf85d first commit 4 年之前 locale.php d01d7cf85d first commit 4 年之前 media-template.php d01d7cf85d first commit 4 年之前 media.php d01d7cf85d first commit 4 年之前 meta.php d01d7cf85d first commit 4 年之前 ms-blogs.php d01d7cf85d first commit 4 年之前 ms-default-constants.php d01d7cf85d first commit 4 年之前 ms-default-filters.php d01d7cf85d first commit 4 年之前 ms-deprecated.php d01d7cf85d first commit 4 年之前 ms-files.php d01d7cf85d first commit 4 年之前 ms-functions.php d01d7cf85d first commit 4 年之前 ms-load.php d01d7cf85d first commit 4 年之前 ms-network.php d01d7cf85d first commit 4 年之前 ms-settings.php d01d7cf85d first commit 4 年之前 ms-site.php d01d7cf85d first commit 4 年之前 nav-menu-template.php d01d7cf85d first commit 4 年之前 nav-menu.php d01d7cf85d first commit 4 年之前 option.php d01d7cf85d first commit 4 年之前 pluggable-deprecated.php d01d7cf85d first commit 4 年之前 pluggable.php d01d7cf85d first commit 4 年之前 plugin.php d01d7cf85d first commit 4 年之前 post-formats.php d01d7cf85d first commit 4 年之前 post-template.php d01d7cf85d first commit 4 年之前 post-thumbnail-template.php d01d7cf85d first commit 4 年之前 post.php d01d7cf85d first commit 4 年之前 query.php d01d7cf85d first commit 4 年之前 registration-functions.php d01d7cf85d first commit 4 年之前 registration.php d01d7cf85d first commit 4 年之前 rest-api.php d01d7cf85d first commit 4 年之前 revision.php d01d7cf85d first commit 4 年之前 rewrite.php d01d7cf85d first commit 4 年之前 robots-template.php d01d7cf85d first commit 4 年之前 rss-functions.php d01d7cf85d first commit 4 年之前 rss.php d01d7cf85d first commit 4 年之前 script-loader.php d01d7cf85d first commit 4 年之前 session.php d01d7cf85d first commit 4 年之前 shortcodes.php d01d7cf85d first commit 4 年之前 sitemaps.php d01d7cf85d first commit 4 年之前 spl-autoload-compat.php d01d7cf85d first commit 4 年之前 taxonomy.php d01d7cf85d first commit 4 年之前 template-canvas.php d01d7cf85d first commit 4 年之前 template-loader.php d01d7cf85d first commit 4 年之前 template.php d01d7cf85d first commit 4 年之前 theme-i18n.json d01d7cf85d first commit 4 年之前 theme-templates.php d01d7cf85d first commit 4 年之前 theme.json d01d7cf85d first commit 4 年之前 theme.php d01d7cf85d first commit 4 年之前 update.php d01d7cf85d first commit 4 年之前 user.php d01d7cf85d first commit 4 年之前 vars.php d01d7cf85d first commit 4 年之前 version.php d01d7cf85d first commit 4 年之前 widgets.php d01d7cf85d first commit 4 年之前 wlwmanifest.xml d01d7cf85d first commit 4 年之前 wp-db.php d01d7cf85d first commit 4 年之前 wp-diff.php d01d7cf85d first commit 4 年之前 tum/whitesports - Gogs: Simplico Git Service

Aucune description

exceptions.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php declare(strict_types = 1);
  2. // phpcs:ignoreFile PSR1.Classes.ClassDeclaration
  3. namespace MailPoet;
  4. if (!defined('ABSPATH')) exit;
  5. /**
  6. * Provides information for converting exceptions to HTTP responses.
  7. */
  8. interface HttpAwareException {
  9. public function getHttpStatusCode(): int;
  10. }
  11. /**
  12. * Frames all MailPoet exceptions ("$e instanceof MailPoet\Exception").
  13. */
  14. abstract class Exception extends \Exception {
  15. /** @var string[] */
  16. private $errors = [];
  17. final public function __construct($message = '', $code = 0, \Throwable $previous = null) {
  18. parent::__construct($message, $code, $previous);
  19. }
  20. public static function create(\Throwable $previous = null): self {
  21. return new static('', 0, $previous);
  22. }
  23. public function withMessage(string $message): self {
  24. $this->message = $message;
  25. return $this;
  26. }
  27. public function withCode(int $code): self {
  28. $this->code = $code;
  29. return $this;
  30. }
  31. public function withErrors(array $errors): self {
  32. $this->errors = $errors;
  33. return $this;
  34. }
  35. public function getErrors(): array {
  36. return $this->errors;
  37. }
  38. }
  39. /**
  40. * USE: Generic runtime error. When possible, use a more specific exception instead.
  41. * API: 500 Server Error (not HTTP-aware)
  42. */
  43. class RuntimeException extends Exception {}
  44. /**
  45. * USE: When wrong data VALUE is received.
  46. * API: 400 Bad Request
  47. */
  48. class UnexpectedValueException extends RuntimeException implements HttpAwareException {
  49. public function getHttpStatusCode(): int {
  50. return 400;
  51. }
  52. }
  53. /**
  54. * USE: When an action is forbidden for given actor (although generally valid).
  55. * API: 403 Forbidden
  56. */
  57. class AccessDeniedException extends UnexpectedValueException implements HttpAwareException {
  58. public function getHttpStatusCode(): int {
  59. return 403;
  60. }
  61. }
  62. /**
  63. * USE: When the main resource we're interested in doesn't exist.
  64. * API: 404 Not Found
  65. */
  66. class NotFoundException extends UnexpectedValueException implements HttpAwareException {
  67. public function getHttpStatusCode(): int {
  68. return 404;
  69. }
  70. }
  71. /**
  72. * USE: When the main action produces conflict (i.e. duplicate key).
  73. * API: 409 Conflict
  74. */
  75. class ConflictException extends UnexpectedValueException implements HttpAwareException {
  76. public function getHttpStatusCode(): int {
  77. return 409;
  78. }
  79. }
  80. /**
  81. * USE: An application state that should not occur. Can be subclassed for feature-specific exceptions.
  82. * API: 500 Server Error (not HTTP-aware)
  83. */
  84. class InvalidStateException extends RuntimeException {}