Skip to content

Commit

Permalink
Update message signatures for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
zbateson committed Jul 25, 2018
1 parent c2d75d3 commit 37aad30
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 29 deletions.
15 changes: 7 additions & 8 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,15 @@ public function isMime()
* $stringOrHandle is expected to be in UTF-8 regardless of the target
* charset.
*
* @param string|resource $stringOrHandle
* @param string|resource|StreamInterface $resource
* @param string $charset
*/
public function setTextPart($stringOrHandle, $charset = 'UTF-8')
public function setTextPart($resource, $charset = 'UTF-8')
{
$this->messageHelperService
->getMultipartHelper()
->setContentPartForMimeType(
$this, 'text/plain', $stringOrHandle, $charset
$this, 'text/plain', $resource, $charset
);
}

Expand All @@ -331,15 +331,15 @@ public function setTextPart($stringOrHandle, $charset = 'UTF-8')
* $stringOrHandle is expected to be in UTF-8 regardless of the target
* charset.
*
* @param string|resource $stringOrHandle
* @param string|resource|StreamInterface $resource
* @param string $charset
*/
public function setHtmlPart($stringOrHandle, $charset = 'UTF-8')
public function setHtmlPart($resource, $charset = 'UTF-8')
{
$this->messageHelperService
->getMultipartHelper()
->setContentPartForMimeType(
$this, 'text/html', $stringOrHandle, $charset
$this, 'text/html', $resource, $charset
);
}

Expand Down Expand Up @@ -462,8 +462,7 @@ public function addAttachmentPartFromFile($file, $mimeType, $filename = null, $d
* Returns a string containing the entire body of a signed message for
* verification or calculating a signature.
*
* @return string or null if the message doesn't have any children, or the
* child returns null for getHandle
* @return string or null if the message doesn't have any children
*/
public function getSignedMessageAsString()
{
Expand Down
18 changes: 8 additions & 10 deletions src/Message/Part/MessagePart.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public abstract function isMime();
*
* @return resource the resource handle
*/
public function getHandle()
public function getResourceHandle()
{
return StreamWrapper::getResource($this->getStream());
}
Expand Down Expand Up @@ -364,14 +364,14 @@ public function detachContentStream()
}

/**
* Sets the content of the part to the passed string.
* Sets the content of the part to the passed resource.
*
* @param string|resource $stringOrHandle
* @param string|resource|StreamInterface $resource
* @param string $charset
*/
public function setContent($stringOrHandle, $charset = MailMimeParser::DEFAULT_CHARSET)
public function setContent($resource, $charset = MailMimeParser::DEFAULT_CHARSET)
{
$stream = Psr7\stream_for($stringOrHandle);
$stream = Psr7\stream_for($resource);
$this->attachContentStream($stream, $charset);
// this->onChange called in attachContentStream
}
Expand All @@ -385,12 +385,10 @@ public function save($streamOrHandle)
{
$message = $this->getStream();
$message->rewind();
if (!($streamOrHandle instanceof StreamInterface)) {
$streamOrHandle = Psr7\stream_for($streamOrHandle);
}
Psr7\copy_to_stream($message, $streamOrHandle);
$stream = Psr7\stream_for($streamOrHandle);
Psr7\copy_to_stream($message, $stream);
// don't close when out of scope
$streamOrHandle->detach();
$stream->detach();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/MailMimeParser/Message/Part/MessagePartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ public function testNewInstance()
$this->assertNull($messagePart->getContentResourceHandle());
$this->assertNull($messagePart->getContent());
$this->assertNull($messagePart->getParent());
$this->assertEquals('habibi', stream_get_contents($messagePart->getHandle()));
$this->assertEquals('habibi', stream_get_contents($messagePart->getResourceHandle()));
}

public function testPartStreamHandle()
{
$messagePart = $this->getMessagePart('mucha agua');
$this->assertFalse($messagePart->hasContent());
$this->assertNull($messagePart->getContentResourceHandle());
$this->assertNotNull($messagePart->getHandle());
$handle = $messagePart->getHandle();
$this->assertNotNull($messagePart->getResourceHandle());
$handle = $messagePart->getResourceHandle();
$this->assertEquals('mucha agua', stream_get_contents($handle));
}

Expand Down
16 changes: 8 additions & 8 deletions tests/MailMimeParser/Message/Part/MimePartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public function testCreateChildrenAndGetChildren()
{
$part = $this->newMimePart($this->getMockedPartBuilderWithChildren());
$this->assertEquals(3, $part->getChildCount());
$this->assertEquals('child0', stream_get_contents($part->getChild(0)->getHandle()));
$this->assertEquals('child1', stream_get_contents($part->getChild(1)->getHandle()));
$this->assertEquals('child2', stream_get_contents($part->getChild(2)->getHandle()));
$this->assertEquals('child0', stream_get_contents($part->getChild(0)->getResourceHandle()));
$this->assertEquals('child1', stream_get_contents($part->getChild(1)->getResourceHandle()));
$this->assertEquals('child2', stream_get_contents($part->getChild(2)->getResourceHandle()));
$children = [
$part->getChild(0),
$part->getChild(1),
Expand All @@ -138,11 +138,11 @@ public function testCreateChildrenAndGetParts()
$this->assertSame($children[1], $part->getPart(3));
$this->assertSame($children[2], $part->getPart(4));

$this->assertEquals('habibi', stream_get_contents($part->getPart(0)->getHandle()));
$this->assertEquals('child0', stream_get_contents($part->getPart(1)->getHandle()));
$this->assertEquals('nested', stream_get_contents($part->getPart(2)->getHandle()));
$this->assertEquals('child1', stream_get_contents($part->getPart(3)->getHandle()));
$this->assertEquals('child2', stream_get_contents($part->getPart(4)->getHandle()));
$this->assertEquals('habibi', stream_get_contents($part->getPart(0)->getResourceHandle()));
$this->assertEquals('child0', stream_get_contents($part->getPart(1)->getResourceHandle()));
$this->assertEquals('nested', stream_get_contents($part->getPart(2)->getResourceHandle()));
$this->assertEquals('child1', stream_get_contents($part->getPart(3)->getResourceHandle()));
$this->assertEquals('child2', stream_get_contents($part->getPart(4)->getResourceHandle()));

$allParts = [ $part, $children[0], $nested, $children[1], $children[2]];
$this->assertEquals($allParts, $part->getAllParts());
Expand Down

0 comments on commit 37aad30

Please sign in to comment.