Dashboard sipadu mbip
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RawMessage.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\Mime;
  11. /**
  12. * @author Fabien Potencier <fabien@symfony.com>
  13. *
  14. * @experimental in 4.3
  15. */
  16. class RawMessage implements \Serializable
  17. {
  18. private $message;
  19. /**
  20. * @param iterable|string $message
  21. */
  22. public function __construct($message)
  23. {
  24. $this->message = $message;
  25. }
  26. public function toString(): string
  27. {
  28. if (\is_string($this->message)) {
  29. return $this->message;
  30. }
  31. return $this->message = implode('', iterator_to_array($this->message, false));
  32. }
  33. public function toIterable(): iterable
  34. {
  35. if (\is_string($this->message)) {
  36. yield $this->message;
  37. return;
  38. }
  39. $message = '';
  40. foreach ($this->message as $chunk) {
  41. $message .= $chunk;
  42. yield $chunk;
  43. }
  44. $this->message = $message;
  45. }
  46. /**
  47. * @internal
  48. */
  49. final public function serialize()
  50. {
  51. return serialize($this->__serialize());
  52. }
  53. /**
  54. * @internal
  55. */
  56. final public function unserialize($serialized)
  57. {
  58. $this->__unserialize(unserialize($serialized));
  59. }
  60. public function __serialize(): array
  61. {
  62. return [$this->message];
  63. }
  64. public function __unserialize(array $data): void
  65. {
  66. [$this->message] = $data;
  67. }
  68. }