@@ -31,6 +31,8 @@ class Attachment
31
31
private $ disposition ;
32
32
/** @var string File name */
33
33
private $ fileName ;
34
+ /** @var ?string Contents */
35
+ private $ _contents ;
34
36
35
37
/**
36
38
* Attachment constructor.
@@ -47,6 +49,28 @@ public function __construct(string $fileName)
47
49
}
48
50
}
49
51
52
+ public function __serialize (): array
53
+ {
54
+ return [
55
+ 'id ' => $ this ->id ,
56
+ 'type ' => $ this ->getType (),
57
+ 'name ' => $ this ->name ,
58
+ 'disposition ' => $ this ->disposition ,
59
+ 'fileName ' => $ this ->fileName ,
60
+ 'contents ' => $ this ->getContents (),
61
+ ];
62
+ }
63
+
64
+ public function __unserialize (array $ data ): void
65
+ {
66
+ $ this ->id = $ data ['id ' ];
67
+ $ this ->type = $ data ['type ' ];
68
+ $ this ->name = $ data ['name ' ];
69
+ $ this ->disposition = $ data ['disposition ' ];
70
+ $ this ->fileName = $ data ['fileName ' ];
71
+ $ this ->_contents = $ data ['contents ' ];
72
+ }
73
+
50
74
/**
51
75
* Get content ID.
52
76
*
@@ -175,6 +199,10 @@ public function setDisposition(string $disposition): Attachment
175
199
*/
176
200
public function getContents ()
177
201
{
202
+ if (null !== $ this ->_contents ) {
203
+ return $ this ->_contents ;
204
+ }
205
+
178
206
return file_get_contents ($ this ->fileName );
179
207
}
180
208
}
0 commit comments