@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 119 lines 2.2 kB view raw
1<?php 2 3namespace PhpMimeMailParser; 4 5/** 6 * Mime Part 7 * Represents the results of mailparse_msg_get_part_data() 8 * 9 * Note ArrayAccess::offsetSet() cannot modify deeply nestated arrays. 10 * When modifying use getPart() and setPart() for deep nested data modification 11 * 12 * @example 13 * 14 * $MimePart['headers']['from'] = 'modified@example.com' // fails 15 * 16 * // correct 17 * $part = $MimePart->getPart(); 18 * $part['headers']['from'] = 'modified@example.com'; 19 * $MimePart->setPart($part); 20 */ 21class MimePart implements \ArrayAccess 22{ 23 /** 24 * Internal mime part 25 * 26 * @var array 27 */ 28 protected $part = array(); 29 30 /** 31 * Immutable Part Id 32 * 33 * @var string 34 */ 35 private $id; 36 37 /** 38 * Create a mime part 39 * 40 * @param array $part 41 * @param string $id 42 */ 43 public function __construct($id, array $part) 44 { 45 $this->part = $part; 46 $this->id = $id; 47 } 48 49 /** 50 * Retrieve the part Id 51 * 52 * @return string 53 */ 54 public function getId() 55 { 56 return $this->id; 57 } 58 59 /** 60 * Retrieve the part data 61 * 62 * @return array 63 */ 64 public function getPart() 65 { 66 return $this->part; 67 } 68 69 /** 70 * Set the mime part data 71 * 72 * @param array $part 73 * @return void 74 */ 75 public function setPart(array $part) 76 { 77 $this->part = $part; 78 } 79 80 /** 81 * ArrayAccess 82 */ 83 #[\ReturnTypeWillChange] 84 public function offsetSet($offset, $value) 85 { 86 if (is_null($offset)) { 87 $this->part[] = $value; 88 return; 89 } 90 $this->part[$offset] = $value; 91 } 92 93 /** 94 * ArrayAccess 95 */ 96 #[\ReturnTypeWillChange] 97 public function offsetExists($offset) 98 { 99 return isset($this->part[$offset]); 100 } 101 102 /** 103 * ArrayAccess 104 */ 105 #[\ReturnTypeWillChange] 106 public function offsetUnset($offset) 107 { 108 unset($this->part[$offset]); 109 } 110 111 /** 112 * ArrayAccess 113 */ 114 #[\ReturnTypeWillChange] 115 public function offsetGet($offset) 116 { 117 return isset($this->part[$offset]) ? $this->part[$offset] : null; 118 } 119}