File tree 1 file changed +24
-3
lines changed
src/Symfony/Component/Mime
1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change 18
18
*/
19
19
class RawMessage
20
20
{
21
- private iterable |string $ message ;
21
+ /** @var iterable|string|resource */
22
+ private $ message ;
22
23
private bool $ isGeneratorClosed ;
23
24
24
25
public function __construct (iterable |string $ message )
25
26
{
26
27
$ this ->message = $ message ;
27
28
}
28
29
30
+ public function __destruct ()
31
+ {
32
+ if (\is_resource ($ this ->message )) {
33
+ fclose ($ this ->message );
34
+ }
35
+ }
36
+
29
37
public function toString (): string
30
38
{
31
39
if (\is_string ($ this ->message )) {
32
40
return $ this ->message ;
33
41
}
34
42
43
+ if (\is_resource ($ this ->message )) {
44
+ return stream_get_contents ($ this ->message , -1 , 0 );
45
+ }
46
+
35
47
$ message = '' ;
36
48
foreach ($ this ->message as $ chunk ) {
37
49
$ message .= $ chunk ;
@@ -53,10 +65,19 @@ public function toIterable(): iterable
53
65
return ;
54
66
}
55
67
68
+ if (\is_resource ($ this ->message )) {
69
+ rewind ($ this ->message );
70
+ while ($ line = fgets ($ this ->message )) {
71
+ yield $ line ;
72
+ }
73
+
74
+ return ;
75
+ }
76
+
56
77
if ($ this ->message instanceof \Generator) {
57
- $ message = '' ;
78
+ $ message = fopen ( ' php://temp ' , ' w+ ' ) ;
58
79
foreach ($ this ->message as $ chunk ) {
59
- $ message .= $ chunk ;
80
+ fwrite ( $ message, $ chunk) ;
60
81
yield $ chunk ;
61
82
}
62
83
$ this ->isGeneratorClosed = !$ this ->message ->valid ();
You can’t perform that action at this time.
0 commit comments