MessageBag.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Contract;
  12. interface MessageBag
  13. {
  14. /**
  15. * Get the keys present in the message bag.
  16. */
  17. public function keys(): array;
  18. /**
  19. * Add a message to the bag.
  20. */
  21. public function add(string $key, string $message): MessageBag;
  22. /**
  23. * Merge a new array of messages into the bag.
  24. *
  25. * @param array|MessageProvider $messages
  26. * @return $this
  27. */
  28. public function merge($messages);
  29. /**
  30. * Determine if messages exist for a given key.
  31. *
  32. * @param array|string $key
  33. */
  34. public function has($key): bool;
  35. /**
  36. * Get the first message from the bag for a given key.
  37. */
  38. public function first(?string $key = null, ?string $format = null): string;
  39. /**
  40. * Get all of the messages from the bag for a given key.
  41. */
  42. public function get(string $key, ?string $format = null): array;
  43. /**
  44. * Get all of the messages for every key in the bag.
  45. */
  46. public function all(?string $format = null): array;
  47. /**
  48. * Get the raw messages in the container.
  49. */
  50. public function getMessages(): array;
  51. /**
  52. * Get the default message format.
  53. */
  54. public function getFormat(): string;
  55. /**
  56. * Set the default message format.
  57. *
  58. * @return $this
  59. */
  60. public function setFormat(string $format = ':message');
  61. /**
  62. * Determine if the message bag has any messages.
  63. */
  64. public function isEmpty(): bool;
  65. /**
  66. * Determine if the message bag has any messages.
  67. */
  68. public function isNotEmpty(): bool;
  69. /**
  70. * Get the number of messages in the container.
  71. */
  72. public function count(): int;
  73. }