Skip to content

Commit 7bccf26

Browse files
committed
Add missing JSON and array representations of objects
1 parent 7ea0f30 commit 7bccf26

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

src/Address.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
namespace DirectoryTree\ImapEngine;
44

5-
class Address
5+
use Illuminate\Contracts\Support\Arrayable;
6+
use JsonSerializable;
7+
8+
class Address implements Arrayable, JsonSerializable
69
{
710
/**
811
* Constructor.
@@ -27,4 +30,23 @@ public function name(): string
2730
{
2831
return $this->name;
2932
}
33+
34+
/**
35+
* Get the array representation of the address.
36+
*/
37+
public function toArray(): array
38+
{
39+
return [
40+
'email' => $this->email,
41+
'name' => $this->name,
42+
];
43+
}
44+
45+
/**
46+
* Get the JSON representation of the address.
47+
*/
48+
public function jsonSerialize(): array
49+
{
50+
return $this->toArray();
51+
}
3052
}

src/Attachment.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace DirectoryTree\ImapEngine;
44

5+
use Illuminate\Contracts\Support\Arrayable;
6+
use JsonSerializable;
57
use Psr\Http\Message\StreamInterface;
68
use Symfony\Component\Mime\MimeTypes;
79

8-
class Attachment
10+
class Attachment implements Arrayable, JsonSerializable
911
{
1012
/**
1113
* Constructor.
@@ -71,4 +73,24 @@ public function extension(): ?string
7173

7274
return null;
7375
}
76+
77+
/**
78+
* Get the array representation of the attachment.
79+
*/
80+
public function toArray(): array
81+
{
82+
return [
83+
'filename' => $this->filename,
84+
'contentType' => $this->contentType,
85+
'contents' => $this->contents(),
86+
];
87+
}
88+
89+
/**
90+
* Get the JSON representation of the attachment.
91+
*/
92+
public function jsonSerialize(): array
93+
{
94+
return $this->toArray();
95+
}
7496
}

src/Folder.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
use DirectoryTree\ImapEngine\Enums\ImapFetchIdentifier;
88
use DirectoryTree\ImapEngine\Exceptions\Exception;
99
use DirectoryTree\ImapEngine\Exceptions\ImapCapabilityException;
10+
use Illuminate\Contracts\Support\Arrayable;
11+
use JsonSerializable;
1012

11-
class Folder
13+
class Folder implements Arrayable, JsonSerializable
1214
{
1315
/**
1416
* The folder's cached capabilities.
@@ -206,4 +208,24 @@ protected function capabilities(): array
206208
{
207209
return $this->capabilities ??= $this->mailbox->capabilities();
208210
}
211+
212+
/**
213+
* Get the array representation of the folder.
214+
*/
215+
public function toArray(): array
216+
{
217+
return [
218+
'path' => $this->path,
219+
'flags' => $this->flags,
220+
'delimiter' => $this->delimiter,
221+
];
222+
}
223+
224+
/**
225+
* Get the JSON representation of the folder.
226+
*/
227+
public function jsonSerialize(): array
228+
{
229+
return $this->toArray();
230+
}
209231
}

0 commit comments

Comments
 (0)