Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Part.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Mime.php';
26 
36 {
37 
44 
51 
57  public $id;
58 
64  public $disposition;
65 
71  public $filename;
72 
78  public $description;
79 
85  public $charset;
86 
92  public $boundary;
93 
99  public $location;
100 
106  public $language;
107 
113  protected $_content;
114 
118  protected $_isStream = false;
119 
127  public function __construct($content)
128  {
129  $this->_content = $content;
130  if (is_resource($content)) {
131  $this->_isStream = true;
132  }
133  }
134 
149  public function isStream()
150  {
151  return $this->_isStream;
152  }
153 
161  public function getEncodedStream()
162  {
163  if (!$this->_isStream) {
164  #require_once 'Zend/Mime/Exception.php';
165  throw new Zend_Mime_Exception(
166  'Attempt to get a stream from a string part'
167  );
168  }
169 
170  //stream_filter_remove(); // ??? is that right?
171  switch ($this->encoding) {
173  $filter = stream_filter_append(
174  $this->_content,
175  'convert.quoted-printable-encode',
176  STREAM_FILTER_READ,
177  array(
178  'line-length' => 76,
179  'line-break-chars' => Zend_Mime::LINEEND
180  )
181  );
182  if (!is_resource($filter)) {
183  #require_once 'Zend/Mime/Exception.php';
184  throw new Zend_Mime_Exception(
185  'Failed to append quoted-printable filter'
186  );
187  }
188  break;
189 
191  $filter = stream_filter_append(
192  $this->_content,
193  'convert.base64-encode',
194  STREAM_FILTER_READ,
195  array(
196  'line-length' => 76,
197  'line-break-chars' => Zend_Mime::LINEEND
198  )
199  );
200  if (!is_resource($filter)) {
201  #require_once 'Zend/Mime/Exception.php';
202  throw new Zend_Mime_Exception(
203  'Failed to append base64 filter'
204  );
205  }
206  break;
207 
208  default:
209  }
210 
211  return $this->_content;
212  }
213 
221  public function getContent($EOL = Zend_Mime::LINEEND)
222  {
223  if ($this->_isStream) {
224  return stream_get_contents($this->getEncodedStream());
225  } else {
226  return Zend_Mime::encode($this->_content, $this->encoding, $EOL);
227  }
228  }
229 
235  public function getRawContent()
236  {
237  if ($this->_isStream) {
238  return stream_get_contents($this->_content);
239  } else {
240  return $this->_content;
241  }
242  }
243 
250  public function getHeadersArray($EOL = Zend_Mime::LINEEND)
251  {
252  $headers = array();
253 
254  $contentType = $this->type;
255  if ($this->charset) {
256  $contentType .= '; charset=' . $this->charset;
257  }
258 
259  if ($this->boundary) {
260  $contentType .= ';' . $EOL
261  . " boundary=\"" . $this->boundary . '"';
262  }
263 
264  $headers[] = array(
265  'Content-Type',
266  $contentType
267  );
268 
269  if ($this->encoding) {
270  $headers[] = array(
271  'Content-Transfer-Encoding',
272  $this->encoding
273  );
274  }
275 
276  if ($this->id) {
277  $headers[] = array(
278  'Content-ID',
279  '<' . $this->id . '>'
280  );
281  }
282 
283  if ($this->disposition) {
285  if ($this->filename) {
286  $disposition .= '; filename="' . $this->filename . '"';
287  }
288  $headers[] = array(
289  'Content-Disposition',
291  );
292  }
293 
294  if ($this->description) {
295  $headers[] = array(
296  'Content-Description',
297  $this->description
298  );
299  }
300 
301  if ($this->location) {
302  $headers[] = array(
303  'Content-Location',
304  $this->location
305  );
306  }
307 
308  if ($this->language) {
309  $headers[] = array(
310  'Content-Language',
311  $this->language
312  );
313  }
314 
315  return $headers;
316  }
317 
324  public function getHeaders($EOL = Zend_Mime::LINEEND)
325  {
326  $res = '';
327  foreach ($this->getHeadersArray($EOL) as $header) {
328  $res .= $header[0] . ': ' . $header[1] . $EOL;
329  }
330 
331  return $res;
332  }
333 }
static encode($str, $encoding, $EOL=self::LINEEND)
Definition: Mime.php:621
const ENCODING_QUOTEDPRINTABLE
Definition: Mime.php:37
const TYPE_OCTETSTREAM
Definition: Mime.php:32
const ENCODING_BASE64
Definition: Mime.php:38
const ENCODING_8BIT
Definition: Mime.php:36
__construct($content)
Definition: Part.php:127
const LINEEND
Definition: Mime.php:42
getEncodedStream()
Definition: Part.php:161
getContent($EOL=Zend_Mime::LINEEND)
Definition: Part.php:221
getHeadersArray($EOL=Zend_Mime::LINEEND)
Definition: Part.php:250
getRawContent()
Definition: Part.php:235
getHeaders($EOL=Zend_Mime::LINEEND)
Definition: Part.php:324