ChatMessage.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Notifier\Message;
  11. use Symfony\Component\Notifier\Notification\Notification;
  12. /**
  13. * @author Fabien Potencier <fabien@symfony.com>
  14. *
  15. * @experimental in 5.1
  16. */
  17. final class ChatMessage implements MessageInterface
  18. {
  19. private $transport;
  20. private $subject;
  21. private $options;
  22. private $notification;
  23. public function __construct(string $subject, MessageOptionsInterface $options = null)
  24. {
  25. $this->subject = $subject;
  26. $this->options = $options;
  27. }
  28. public static function fromNotification(Notification $notification): self
  29. {
  30. $message = new self($notification->getSubject());
  31. $message->notification = $notification;
  32. return $message;
  33. }
  34. /**
  35. * @return $this
  36. */
  37. public function subject(string $subject): self
  38. {
  39. $this->subject = $subject;
  40. return $this;
  41. }
  42. public function getSubject(): string
  43. {
  44. return $this->subject;
  45. }
  46. public function getRecipientId(): ?string
  47. {
  48. return $this->options ? $this->options->getRecipientId() : null;
  49. }
  50. /**
  51. * @return $this
  52. */
  53. public function options(MessageOptionsInterface $options): self
  54. {
  55. $this->options = $options;
  56. return $this;
  57. }
  58. public function getOptions(): ?MessageOptionsInterface
  59. {
  60. return $this->options;
  61. }
  62. /**
  63. * @return $this
  64. */
  65. public function transport(string $transport): self
  66. {
  67. $this->transport = $transport;
  68. return $this;
  69. }
  70. public function getTransport(): ?string
  71. {
  72. return $this->transport;
  73. }
  74. public function getNotification(): ?Notification
  75. {
  76. return $this->notification;
  77. }
  78. }