1 | <?php |
||
23 | class MimePart |
||
24 | { |
||
25 | /** |
||
26 | * @var \ZBateson\MailMimeParser\Header\HeaderFactory the HeaderFactory |
||
27 | * object used for created headers |
||
28 | */ |
||
29 | protected $headerFactory; |
||
30 | |||
31 | /** |
||
32 | * @var \ZBateson\MailMimeParser\Header\AbstractHeader[] array of header |
||
33 | * objects |
||
34 | */ |
||
35 | protected $headers; |
||
36 | |||
37 | /** |
||
38 | * @var \ZBateson\MailMimeParser\MimePart parent part |
||
39 | */ |
||
40 | protected $parent; |
||
41 | |||
42 | /** |
||
43 | * @var resource the content's resource handle |
||
44 | */ |
||
45 | protected $handle; |
||
46 | |||
47 | /** |
||
48 | * Sets up class dependencies. |
||
49 | * |
||
50 | * @param HeaderFactory $headerFactory |
||
51 | */ |
||
52 | 8 | public function __construct(HeaderFactory $headerFactory) |
|
56 | |||
57 | /** |
||
58 | * Closes the attached resource handle. |
||
59 | */ |
||
60 | 8 | public function __destruct() |
|
66 | |||
67 | /** |
||
68 | * Returns true if there's a content stream associated with the part. |
||
69 | * |
||
70 | * @return boolean |
||
71 | */ |
||
72 | 1 | public function hasContent() |
|
79 | |||
80 | /** |
||
81 | * Attaches the resource handle for the part's content. The attached handle |
||
82 | * is closed when the MimePart object is destroyed. |
||
83 | * |
||
84 | * @param resource $contentHandle |
||
85 | */ |
||
86 | 2 | public function attachContentResourceHandle($contentHandle) |
|
90 | |||
91 | /** |
||
92 | * Returns the resource stream handle for the part's content. |
||
93 | * |
||
94 | * The resource is automatically closed by MimePart's destructor and should |
||
95 | * not be closed otherwise. |
||
96 | * |
||
97 | * @return resource |
||
98 | */ |
||
99 | 1 | public function getContentResourceHandle() |
|
103 | |||
104 | /** |
||
105 | * Adds a header with the given $name and $value. |
||
106 | * |
||
107 | * Creates a new \ZBateson\MailMimeParser\Header\AbstractHeader object and |
||
108 | * registers it as a header. |
||
109 | * |
||
110 | * @param string $name |
||
111 | * @param string $value |
||
112 | */ |
||
113 | 3 | public function setRawHeader($name, $value) |
|
117 | |||
118 | /** |
||
119 | * Returns the AbstractHeader object for the header with the given $name |
||
120 | * |
||
121 | * Note that mime headers aren't case sensitive. |
||
122 | * |
||
123 | * @param string $name |
||
124 | * @return \ZBateson\MailMimeParser\Header\Header |
||
125 | */ |
||
126 | 5 | public function getHeader($name) |
|
127 | { |
||
128 | 5 | if (isset($this->headers[strtolower($name)])) { |
|
129 | 3 | return $this->headers[strtolower($name)]; |
|
130 | } |
||
131 | 2 | return null; |
|
132 | } |
||
133 | |||
134 | /** |
||
135 | * Returns the string value for the header with the given $name. |
||
136 | * |
||
137 | * Note that mime headers aren't case sensitive. |
||
138 | * |
||
139 | * @param string $name |
||
140 | * @param string $defaultValue |
||
141 | * @return string |
||
142 | */ |
||
143 | 2 | public function getHeaderValue($name, $defaultValue = null) |
|
144 | { |
||
145 | 2 | $header = $this->getHeader($name); |
|
146 | 2 | if (!empty($header)) { |
|
147 | 1 | return $header->getValue(); |
|
148 | } |
||
149 | 1 | return $defaultValue; |
|
150 | } |
||
151 | |||
152 | /** |
||
153 | * Returns the full array of headers for this part. |
||
154 | * |
||
155 | * @return \ZBateson\MailMimeParser\Header\AbstractHeader[] |
||
156 | */ |
||
157 | 1 | public function getHeaders() |
|
161 | |||
162 | /** |
||
163 | * Returns a parameter of the header $header, given the parameter named |
||
164 | * $param. |
||
165 | * |
||
166 | * Only headers of type |
||
167 | * \ZBateson\MailMimeParser\Header\ParameterHeader have parameters. |
||
168 | * Content-Type and Content-Disposition are examples of headers with |
||
169 | * parameters. "Charset" is a common parameter of Content-Type. |
||
170 | * |
||
171 | * @param string $header |
||
172 | * @param string $param |
||
173 | * @param string $defaultValue |
||
174 | * @return string |
||
175 | */ |
||
176 | 2 | public function getHeaderParameter($header, $param, $defaultValue = null) |
|
177 | { |
||
178 | 2 | $obj = $this->getHeader($header); |
|
179 | 2 | if ($obj && $obj instanceof ParameterHeader) { |
|
180 | 1 | return $obj->getValueFor($param, $defaultValue); |
|
181 | } |
||
182 | 1 | return $defaultValue; |
|
183 | } |
||
184 | |||
185 | /** |
||
186 | * Sets the parent part. |
||
187 | * |
||
188 | * @param \ZBateson\MailMimeParser\MimePart $part |
||
189 | */ |
||
190 | 1 | public function setParent(MimePart $part) |
|
194 | |||
195 | /** |
||
196 | * Returns this part's parent. |
||
197 | * |
||
198 | * @return \ZBateson\MailMimeParser\MimePart |
||
199 | */ |
||
200 | 1 | public function getParent() |
|
204 | } |
||
205 |