Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/metamta/message/PhabricatorMailAttachment.php
12256 views
1
<?php
2
3
final class PhabricatorMailAttachment extends Phobject {
4
5
private $data;
6
private $filename;
7
private $mimetype;
8
private $file;
9
private $filePHID;
10
11
public function __construct($data, $filename, $mimetype) {
12
$this->setData($data);
13
$this->setFilename($filename);
14
$this->setMimeType($mimetype);
15
}
16
17
public function getData() {
18
return $this->data;
19
}
20
21
public function setData($data) {
22
$this->data = $data;
23
return $this;
24
}
25
26
public function getFilename() {
27
return $this->filename;
28
}
29
30
public function setFilename($filename) {
31
$this->filename = $filename;
32
return $this;
33
}
34
35
public function getMimeType() {
36
return $this->mimetype;
37
}
38
39
public function setMimeType($mimetype) {
40
$this->mimetype = $mimetype;
41
return $this;
42
}
43
44
public function toDictionary() {
45
if (!$this->file) {
46
$iterator = new ArrayIterator(array($this->getData()));
47
48
$source = id(new PhabricatorIteratorFileUploadSource())
49
->setName($this->getFilename())
50
->setViewPolicy(PhabricatorPolicies::POLICY_NOONE)
51
->setMIMEType($this->getMimeType())
52
->setIterator($iterator);
53
54
$this->file = $source->uploadFile();
55
}
56
57
return array(
58
'filename' => $this->getFilename(),
59
'mimetype' => $this->getMimeType(),
60
'filePHID' => $this->file->getPHID(),
61
);
62
}
63
64
public static function newFromDictionary(array $dict) {
65
$file = null;
66
67
$file_phid = idx($dict, 'filePHID');
68
if ($file_phid) {
69
$file = id(new PhabricatorFileQuery())
70
->setViewer(PhabricatorUser::getOmnipotentUser())
71
->withPHIDs(array($file_phid))
72
->executeOne();
73
if ($file) {
74
$dict['data'] = $file->loadFileData();
75
}
76
}
77
78
$attachment = new self(
79
idx($dict, 'data'),
80
idx($dict, 'filename'),
81
idx($dict, 'mimetype'));
82
83
if ($file) {
84
$attachment->file = $file;
85
}
86
87
return $attachment;
88
}
89
90
}
91
92