Horde_Mime_Part::appendContents PHP Method

appendContents() public method

Add to the body contents of this part.
public appendContents ( mixed $contents, $options = [] )
$contents mixed The part body. Either a string or a stream resource, or an array containing both. - encoding: (string) The encoding of $contents. DEFAULT: Current transfer encoding value. - usestream: (boolean) If $contents is a stream, should we directly use that stream? DEFAULT: $contents copied to a new stream.
    public function appendContents($contents, $options = array())
    {
        if (empty($this->_contents)) {
            $this->setContents($contents, $options);
        } else {
            $fp = empty($options['usestream']) || !is_resource($contents) ? $this->_writeStream($contents) : $contents;
            $this->_writeStream(empty($options['encoding']) || $options['encoding'] == $this->_transferEncoding ? $fp : $this->_transferDecode($fp, $options['encoding']), array('fp' => $this->_contents));
            unset($this->_temp['sendTransferEncoding']);
        }
    }

Usage Example

Example #1
0
 public function testAppendContents()
 {
     $part = new Horde_Mime_Part();
     $part->appendContents('1');
     $this->assertEquals('1', $part->getContents());
     $part->appendContents('2');
     $this->assertEquals('12', $part->getContents());
     $tmp = fopen('php://temp', 'r+');
     fwrite($tmp, '3');
     rewind($tmp);
     $part->appendContents($tmp);
     $this->assertEquals('123', $part->getContents());
     $tmp = fopen('php://temp', 'r+');
     fwrite($tmp, '5');
     rewind($tmp);
     $part->appendContents(array('4', $tmp, '6'));
     $this->assertEquals('123456', $part->getContents());
 }