Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Zend_Mime_Part Class Reference

Public Member Functions

 __construct ($content)
 
 isStream ()
 
 getEncodedStream ()
 
 getContent ($EOL=Zend_Mime::LINEEND)
 
 getRawContent ()
 
 getHeadersArray ($EOL=Zend_Mime::LINEEND)
 
 getHeaders ($EOL=Zend_Mime::LINEEND)
 

Data Fields

 $type = Zend_Mime::TYPE_OCTETSTREAM
 
 $encoding = Zend_Mime::ENCODING_8BIT
 
 $id
 
 $disposition
 
 $filename
 
 $description
 
 $charset
 
 $boundary
 
 $location
 
 $language
 

Protected Attributes

 $_content
 
 $_isStream = false
 

Detailed Description

Definition at line 35 of file Part.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $content)

create a new Mime Part. The (unencoded) content of the Part as passed as a string or stream

Parameters
mixed$contentString or Stream containing the content

Definition at line 127 of file Part.php.

128  {
129  $this->_content = $content;
130  if (is_resource($content)) {
131  $this->_isStream = true;
132  }
133  }

Member Function Documentation

◆ getContent()

getContent (   $EOL = Zend_Mime::LINEEND)

Get the Content of the current Mime Part in the given encoding.

Parameters
string$EOLLine end; defaults to Zend_Mime::LINEEND
Exceptions
Zend_Mime_Exception
Returns
string

Definition at line 221 of file Part.php.

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  }
static encode($str, $encoding, $EOL=self::LINEEND)
Definition: Mime.php:621
getEncodedStream()
Definition: Part.php:161

◆ getEncodedStream()

getEncodedStream ( )

if this was created with a stream, return a filtered stream for reading the content. very useful for large file attachments.

Returns
mixed Stream
Exceptions
Zend_Mime_Exceptionif not a stream or unable to append filter

Definition at line 161 of file Part.php.

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  }
const ENCODING_QUOTEDPRINTABLE
Definition: Mime.php:37
const ENCODING_BASE64
Definition: Mime.php:38
const LINEEND
Definition: Mime.php:42

◆ getHeaders()

getHeaders (   $EOL = Zend_Mime::LINEEND)

Return the headers for this part as a string

Parameters
string$EOLLine end; defaults to Zend_Mime::LINEEND
Returns
string

Definition at line 324 of file Part.php.

325  {
326  $res = '';
327  foreach ($this->getHeadersArray($EOL) as $header) {
328  $res .= $header[0] . ': ' . $header[1] . $EOL;
329  }
330 
331  return $res;
332  }
getHeadersArray($EOL=Zend_Mime::LINEEND)
Definition: Part.php:250

◆ getHeadersArray()

getHeadersArray (   $EOL = Zend_Mime::LINEEND)

Create and return the array of headers for this MIME part

Parameters
string$EOLLine end; defaults to Zend_Mime::LINEEND
Returns
array

Definition at line 250 of file Part.php.

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  }

◆ getRawContent()

getRawContent ( )

Get the RAW unencoded content from this part

Returns
string

Definition at line 235 of file Part.php.

236  {
237  if ($this->_isStream) {
238  return stream_get_contents($this->_content);
239  } else {
240  return $this->_content;
241  }
242  }

◆ isStream()

isStream ( )
Todo:

setters/getters

error checking for setting $type

error checking for setting $encoding

check if this part can be read as a stream. if true, getEncodedStream can be called, otherwise only getContent can be used to fetch the encoded content of the part

Returns
bool

Definition at line 149 of file Part.php.

150  {
151  return $this->_isStream;
152  }

Field Documentation

◆ $_content

$_content
protected

Definition at line 113 of file Part.php.

◆ $_isStream

$_isStream = false
protected

Definition at line 118 of file Part.php.

◆ $boundary

$boundary

Definition at line 92 of file Part.php.

◆ $charset

$charset

Definition at line 85 of file Part.php.

◆ $description

$description

Definition at line 78 of file Part.php.

◆ $disposition

$disposition

Definition at line 64 of file Part.php.

◆ $encoding

Definition at line 50 of file Part.php.

◆ $filename

$filename

Definition at line 71 of file Part.php.

◆ $id

$id

Definition at line 57 of file Part.php.

◆ $language

$language

Definition at line 106 of file Part.php.

◆ $location

$location

Definition at line 99 of file Part.php.

◆ $type

Definition at line 43 of file Part.php.


The documentation for this class was generated from the following file: