Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'docs/#171-completing-ide-hints' into develop
Browse files Browse the repository at this point in the history
Close #171
  • Loading branch information
Ocramius committed Mar 1, 2018
2 parents 5548138 + 4f61536 commit 0c37b59
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class Address implements Address\AddressInterface
* @param string $email
* @param null|string $name
* @throws Exception\InvalidArgumentException
* @return Address
*/
public function __construct($email, $name = null)
{
Expand Down
4 changes: 4 additions & 0 deletions src/Header/GenericHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class GenericHeader implements HeaderInterface, UnstructuredInterface
*/
protected $encoding;

/**
* @param string $headerLine
* @return GenericHeader
*/
public static function fromString($headerLine)
{
list($name, $value) = self::splitHeaderLine($headerLine);
Expand Down
6 changes: 6 additions & 0 deletions src/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Iterator;
use Traversable;
use Zend\Loader\PluginClassLocator;
use Zend\Mail\Header\GenericHeader;
use Zend\Mail\Header\HeaderInterface;

/**
* Basic mail headers collection functionality
Expand Down Expand Up @@ -478,6 +480,8 @@ public function forceLoading()
public function loadHeader($headerLine)
{
list($name, ) = Header\GenericHeader::splitHeaderLine($headerLine);

/** @var HeaderInterface $class */
$class = $this->getPluginClassLoader()->load($name) ?: Header\GenericHeader::class;
return $class::fromString($headerLine);
}
Expand All @@ -491,6 +495,8 @@ protected function lazyLoadHeader($index)
$current = $this->headers[$index];

$key = $this->headersKeys[$index];

/** @var GenericHeader $class */
$class = ($this->getPluginClassLoader()->load($key)) ?: 'Zend\Mail\Header\GenericHeader';

$encoding = $current->getEncoding();
Expand Down
13 changes: 11 additions & 2 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
namespace Zend\Mail;

use Traversable;
use Zend\Mail\Header\ContentType;
use Zend\Mail\Header\Sender;
use Zend\Mime;

class Message
{
/**
* Content of the message
*
* @var string|object
* @var string|object|Mime\Message
*/
protected $body;

Expand Down Expand Up @@ -302,6 +304,7 @@ public function getReplyTo()
*/
public function setSender($emailOrAddress, $name = null)
{
/** @var Sender $header */
$header = $this->getHeaderByName('sender', __NAMESPACE__ . '\Header\Sender');
$header->setAddress($emailOrAddress, $name);
return $this;
Expand All @@ -318,6 +321,8 @@ public function getSender()
if (! $headers->has('sender')) {
return null;
}

/** @var Sender $header */
$header = $this->getHeaderByName('sender', __NAMESPACE__ . '\Header\Sender');
return $header->getAddress();
}
Expand Down Expand Up @@ -397,6 +402,8 @@ public function setBody($body)
// Multipart content headers
if ($this->body->isMultiPart()) {
$mime = $this->body->getMime();

/** @var ContentType $header */
$header = $this->getHeaderByName('content-type', __NAMESPACE__ . '\Header\ContentType');
$header->setType('multipart/mixed');
$header->addParameter('boundary', $mime->boundary());
Expand All @@ -415,7 +422,7 @@ public function setBody($body)
/**
* Return the currently set message body
*
* @return string|object
* @return object|string|Mime\Message
*/
public function getBody()
{
Expand Down Expand Up @@ -553,6 +560,8 @@ public function toString()
public static function fromString($rawMessage)
{
$message = new static();

/** @var Headers $headers */
$headers = null;
$content = null;
Mime\Decode::splitMessage($rawMessage, $headers, $content, Headers::EOL);
Expand Down
1 change: 1 addition & 0 deletions src/Protocol/Smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public function __construct($host = '127.0.0.1', $port = null, array $config = n
* Set whether or not send QUIT command
*
* @param int $useCompleteQuit use complete quit
* @return bool
*/
public function setUseCompleteQuit($useCompleteQuit)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Transport/Sendmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ protected function prepareRecipients(Mail\Message $message)
throw new Exception\RuntimeException('Invalid email; contains no "To" header');
}

/** @var Mail\Header\To $to */
$to = $headers->get('to');
$list = $to->getAddressList();
if (0 == count($list)) {
Expand Down Expand Up @@ -225,7 +226,7 @@ protected function prepareHeaders(Mail\Message $message)
$headers->removeHeader('To');
$headers->removeHeader('Subject');

// Sanitize the From header
/** @var Mail\Header\From $from Sanitize the From header*/
$from = $headers->get('From');
if ($from) {
foreach ($from->getAddressList() as $address) {
Expand Down

0 comments on commit 0c37b59

Please sign in to comment.