Conditions | 3 |
Paths | 2 |
Total Lines | 17 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
32 | public function parse($attachment, string $attachmentName = null): Mime\Part |
||
33 | { |
||
34 | if (! \is_string($attachment) || ! \is_file($attachment)) { |
||
35 | throw InvalidAttachmentException::fromExpectedType('file path'); |
||
36 | } |
||
37 | |||
38 | $part = new Mime\Part(\fopen($attachment, 'r+b')); |
||
39 | $part->type = $this->finfo->file($attachment); |
||
40 | |||
41 | // Make sure encoding and disposition have a default value |
||
42 | $part->encoding = Mime\Mime::ENCODING_BASE64; |
||
43 | $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT; |
||
44 | |||
45 | // If the attachment name is not defined, use the attachment's \basename |
||
46 | $name = $attachmentName ?? \basename($attachment); |
||
47 | return $this->applyNameToPart($part, $name); |
||
48 | } |
||
49 | } |
||
50 |