Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <fabien@symfony.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Symfony\Component\Mime;
13
 
14
use Symfony\Component\Mime\Exception\LogicException;
15
 
16
/**
17
 * @author Fabien Potencier <fabien@symfony.com>
18
 */
19
class RawMessage
20
{
21
    private $message;
22
 
23
    public function __construct(iterable|string $message)
24
    {
25
        $this->message = $message;
26
    }
27
 
28
    public function toString(): string
29
    {
30
        if (\is_string($this->message)) {
31
            return $this->message;
32
        }
33
        if ($this->message instanceof \Traversable) {
34
            $this->message = iterator_to_array($this->message, false);
35
        }
36
 
37
        return $this->message = implode('', $this->message);
38
    }
39
 
40
    public function toIterable(): iterable
41
    {
42
        if (\is_string($this->message)) {
43
            yield $this->message;
44
 
45
            return;
46
        }
47
 
48
        $message = '';
49
        foreach ($this->message as $chunk) {
50
            $message .= $chunk;
51
            yield $chunk;
52
        }
53
        $this->message = $message;
54
    }
55
 
56
    /**
57
     * @throws LogicException if the message is not valid
58
     */
59
    public function ensureValidity()
60
    {
61
    }
62
 
63
    public function __serialize(): array
64
    {
65
        return [$this->toString()];
66
    }
67
 
68
    public function __unserialize(array $data): void
69
    {
70
        [$this->message] = $data;
71
    }
72
}