Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / metamta / message / PhabricatorMailAttachment.php
blob7cc7f32fe2b1ce299e6d7d841ce1d2e391a5cdb9
1 <?php
3 final class PhabricatorMailAttachment extends Phobject {
5 private $data;
6 private $filename;
7 private $mimetype;
8 private $file;
9 private $filePHID;
11 public function __construct($data, $filename, $mimetype) {
12 $this->setData($data);
13 $this->setFilename($filename);
14 $this->setMimeType($mimetype);
17 public function getData() {
18 return $this->data;
21 public function setData($data) {
22 $this->data = $data;
23 return $this;
26 public function getFilename() {
27 return $this->filename;
30 public function setFilename($filename) {
31 $this->filename = $filename;
32 return $this;
35 public function getMimeType() {
36 return $this->mimetype;
39 public function setMimeType($mimetype) {
40 $this->mimetype = $mimetype;
41 return $this;
44 public function toDictionary() {
45 if (!$this->file) {
46 $iterator = new ArrayIterator(array($this->getData()));
48 $source = id(new PhabricatorIteratorFileUploadSource())
49 ->setName($this->getFilename())
50 ->setViewPolicy(PhabricatorPolicies::POLICY_NOONE)
51 ->setMIMEType($this->getMimeType())
52 ->setIterator($iterator);
54 $this->file = $source->uploadFile();
57 return array(
58 'filename' => $this->getFilename(),
59 'mimetype' => $this->getMimeType(),
60 'filePHID' => $this->file->getPHID(),
64 public static function newFromDictionary(array $dict) {
65 $file = null;
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();
78 $attachment = new self(
79 idx($dict, 'data'),
80 idx($dict, 'filename'),
81 idx($dict, 'mimetype'));
83 if ($file) {
84 $attachment->file = $file;
87 return $attachment;