-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUsMailV2Document.php
More file actions
87 lines (82 loc) · 2.78 KB
/
Copy pathUsMailV2Document.php
File metadata and controls
87 lines (82 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace Mindee\Product\Us\UsMail;
use Mindee\Error\MindeeUnsetException;
use Mindee\Parsing\Common\Prediction;
use Mindee\Parsing\Common\SummaryHelper;
use Mindee\Parsing\Standard\StringField;
/**
* US Mail API version 2.0 document data.
*/
class UsMailV2Document extends Prediction
{
/**
* @var UsMailV2RecipientAddresses The addresses of the recipients.
*/
public UsMailV2RecipientAddresses $recipientAddresses;
/**
* @var StringField[] The names of the recipients.
*/
public array $recipientNames;
/**
* @var UsMailV2SenderAddress The address of the sender.
*/
public UsMailV2SenderAddress $senderAddress;
/**
* @var StringField The name of the sender.
*/
public StringField $senderName;
/**
* @param array $rawPrediction Raw prediction from HTTP response.
* @param integer|null $pageId Page number for multi pages document.
* @throws MindeeUnsetException Throws if a field doesn't appear in the response.
*/
public function __construct(array $rawPrediction, ?int $pageId = null)
{
if (!isset($rawPrediction["recipient_addresses"])) {
throw new MindeeUnsetException();
}
$this->recipientAddresses = new UsMailV2RecipientAddresses(
$rawPrediction["recipient_addresses"],
$pageId
);
if (!isset($rawPrediction["recipient_names"])) {
throw new MindeeUnsetException();
}
$this->recipientNames = $rawPrediction["recipient_names"] == null ? [] : array_map(
fn ($prediction) => new StringField($prediction, $pageId),
$rawPrediction["recipient_names"]
);
if (!isset($rawPrediction["sender_address"])) {
throw new MindeeUnsetException();
}
$this->senderAddress = new UsMailV2SenderAddress(
$rawPrediction["sender_address"],
$pageId
);
if (!isset($rawPrediction["sender_name"])) {
throw new MindeeUnsetException();
}
$this->senderName = new StringField(
$rawPrediction["sender_name"],
$pageId
);
}
/**
* @return string String representation.
*/
public function __toString(): string
{
$senderAddressToFieldList = $this->senderAddress != null ? $this->senderAddress->toFieldList() : "";
$recipientNames = implode(
"\n ",
$this->recipientNames
);
$recipientAddressesSummary = strval($this->recipientAddresses);
$outStr = ":Sender Name: $this->senderName
:Sender Address: $senderAddressToFieldList
:Recipient Names: $recipientNames
:Recipient Addresses: $recipientAddressesSummary
";
return SummaryHelper::cleanOutString($outStr);
}
}