Skip to content

Commit

Permalink
Return the object when is set method.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Apr 13, 2011
1 parent 40e8632 commit f4f3bfe
Showing 1 changed file with 46 additions and 31 deletions.
77 changes: 46 additions & 31 deletions lib/Cake/Network/CakeEmail.php
Expand Up @@ -246,7 +246,7 @@ public function from($email = null, $name = null) {
if ($email === null) {
return $this->_from;
}
$this->_setEmailSingle('_from', $email, $name, __d('cake', 'From requires only 1 email address.'));
return $this->_setEmailSingle('_from', $email, $name, __d('cake', 'From requires only 1 email address.'));
}

/**
Expand All @@ -261,7 +261,7 @@ public function replyTo($email = null, $name = null) {
if ($email === null) {
return $this->_replyTo;
}
$this->_setEmailSingle('_replyTo', $email, $name, __d('cake', 'Reply-To requires only 1 email address.'));
return $this->_setEmailSingle('_replyTo', $email, $name, __d('cake', 'Reply-To requires only 1 email address.'));
}

/**
Expand All @@ -276,7 +276,7 @@ public function readReceipt($email = null, $name = null) {
if ($email === null) {
return $this->_readReceipt;
}
$this->_setEmailSingle('_readReceipt', $email, $name, __d('cake', 'Disposition-Notification-To requires only 1 email address.'));
return $this->_setEmailSingle('_readReceipt', $email, $name, __d('cake', 'Disposition-Notification-To requires only 1 email address.'));
}

/**
Expand All @@ -291,7 +291,7 @@ public function returnPath($email = null, $name = null) {
if ($email === null) {
return $this->_returnPath;
}
$this->_setEmailSingle('_returnPath', $email, $name, __d('cake', 'Return-Path requires only 1 email address.'));
return $this->_setEmailSingle('_returnPath', $email, $name, __d('cake', 'Return-Path requires only 1 email address.'));
}

/**
Expand All @@ -305,18 +305,18 @@ public function to($email = null, $name = null) {
if ($email === null) {
return $this->_to;
}
$this->_setEmail('_to', $email, $name);
return $this->_setEmail('_to', $email, $name);
}

/**
* Add To
*
* @param mixed $email String with email, Array with email as key, name as value or email as value (without name)
* @param string $name
* @return void
* @return object $this
*/
public function addTo($email, $name = null) {
$this->_addEmail('_to', $email, $name);
return $this->_addEmail('_to', $email, $name);
}

/**
Expand All @@ -330,43 +330,43 @@ public function cc($email = null, $name = null) {
if ($email === null) {
return $this->_cc;
}
$this->_setEmail('_cc', $email, $name);
return $this->_setEmail('_cc', $email, $name);
}

/**
* Add Cc
*
* @param mixed $email String with email, Array with email as key, name as value or email as value (without name)
* @param string $name
* @return void
* @return object $this
*/
public function addCc($email, $name = null) {
$this->_addEmail('_cc', $email, $name);
return $this->_addEmail('_cc', $email, $name);
}

/**
* Bcc
*
* @param mixed $email String with email, Array with email as key, name as value or email as value (without name)
* @param string $name
* @return void
* @return mixed
*/
public function bcc($email = null, $name = null) {
if ($email === null) {
return $this->_bcc;
}
$this->_setEmail('_bcc', $email, $name);
return $this->_setEmail('_bcc', $email, $name);
}

/**
* Add Bcc
*
* @param mixed $email String with email, Array with email as key, name as value or email as value (without name)
* @param string $name
* @return void
* @return object $this
*/
public function addBcc($email, $name = null) {
$this->_addEmail('_bcc', $email, $name);
return $this->_addEmail('_bcc', $email, $name);
}

/**
Expand All @@ -375,7 +375,7 @@ public function addBcc($email, $name = null) {
* @param string $varName
* @param mixed $email
* @param mixed $name
* @return void
* @return object $this
* @thrown SocketException
*/
protected function _setEmail($varName, $email, $name) {
Expand All @@ -387,7 +387,7 @@ protected function _setEmail($varName, $email, $name) {
$name = $email;
}
$this->{$varName} = array($email => $name);
return;
return $this;
}
$list = array();
foreach ($email as $key => $value) {
Expand All @@ -400,6 +400,7 @@ protected function _setEmail($varName, $email, $name) {
$list[$key] = $value;
}
$this->{$varName} = $list;
return $this;
}

/**
Expand All @@ -409,7 +410,7 @@ protected function _setEmail($varName, $email, $name) {
* @param mixed $email
* @param string $name
* @param string $throwMessage
* @return void
* @return object $this
* @thrown SocketExpceiton
*/
protected function _setEmailSingle($varName, $email, $name, $throwMessage) {
Expand All @@ -419,6 +420,7 @@ protected function _setEmailSingle($varName, $email, $name, $throwMessage) {
$this->{$varName} = $current;
throw new SocketException($throwMessage);
}
return $this;
}

/**
Expand All @@ -427,7 +429,7 @@ protected function _setEmailSingle($varName, $email, $name, $throwMessage) {
* @param string $varName
* @param mixed $email
* @param mixed $name
* @return void
* @return object $this
*/
protected function _addEmail($varName, $email, $name) {
if (!is_array($email)) {
Expand All @@ -438,7 +440,7 @@ protected function _addEmail($varName, $email, $name) {
$name = $email;
}
$this->{$varName}[$email] = $name;
return;
return $this;
}
$list = array();
foreach ($email as $key => $value) {
Expand All @@ -451,6 +453,7 @@ protected function _addEmail($varName, $email, $name) {
$list[$key] = $value;
}
$this->{$varName} = array_merge($this->{$varName}, $list);
return $this;
}

/**
Expand All @@ -464,34 +467,37 @@ public function subject($subject = null) {
return $this->_subject;
}
$this->_subject = (string)$subject;
return $this;
}

/**
* Sets eaders for the message
*
* @param array Associative array containing headers to be set.
* @return void
* @return object $this
* @thrown SocketException
*/
public function setHeaders($headers) {
if (!is_array($headers)) {
throw new SocketException(__d('cake', '$headers should be an array.'));
}
$this->_headers = $headers;
return $this;
}

/**
* Add header for the message
*
* @param array $headers
* @return void
* @return mixed $this
* @thrown SocketException
*/
public function addHeaders($headers) {
if (!is_array($headers)) {
throw new SocketException(__d('cake', '$headers should be an array.'));
}
$this->_headers = array_merge($this->_headers, $headers);
return $this;
}

/**
Expand Down Expand Up @@ -619,6 +625,7 @@ public function layout($layout = null, $template = null) {
if ($template !== null) {
$this->_template = (string)$template;
}
return $this;
}

/**
Expand All @@ -632,6 +639,7 @@ public function viewRender($viewClass = null) {
return $this->_viewRender;
}
$this->_viewRender = $viewClass;
return $this;
}

/**
Expand All @@ -649,6 +657,7 @@ public function emailFormat($format = null) {
throw new SocketException(__d('cake', 'Format not available.'));
}
$this->_emailFormat = $format;
return $this;
}

/**
Expand All @@ -662,6 +671,7 @@ public function transport($name = null) {
return $this->_transportName;
}
$this->_transportName = (string)$name;
return $this;
}

/**
Expand All @@ -683,6 +693,7 @@ public function messageID($message = null) {
}
$this->_messageId = $message;
}
return $this;
}

/**
Expand All @@ -708,19 +719,21 @@ public function attachments($attachments = null) {
$attach[$name] = $path;
}
$this->_attachments = $attach;
return $this;
}

/**
* Add attachments
*
* @param mixed $attachments String with the filename or array with filenames
* @return void
* @return object $this
* @thrown SocketException
*/
public function addAttachments($attachments) {
$current = $this->_attachments;
$this->attachments($attachments);
$this->_attachments = array_merge($current, $this->_attachments);
return $this;
}

/**
Expand All @@ -736,17 +749,18 @@ public function message() {
* Configuration to use when send email
*
* @param mixed $config String with configuration name (from email.php), array with config or null to return current config
* @return string
* @return mixed
*/
public function config($config = null) {
if (!empty($config)) {
if (is_array($config)) {
$this->_config = $config;
} else {
$this->_config = (string)$config;
}
if (empty($config)) {
return $this->_config;
}
if (is_array($config)) {
$this->_config = $config;
} else {
$this->_config = (string)$config;
}
return $this->_config;
return $this;
}

/**
Expand Down Expand Up @@ -830,7 +844,7 @@ public function send($content = null) {
/**
* Reset all EmailComponent internal variables to be able to send out a new email.
*
* @return void
* @return object $this
*/
public function reset() {
$this->_to = array();
Expand All @@ -853,6 +867,7 @@ public function reset() {
$this->_transportName = 'mail';
$this->_attachments = array();
$this->_config = 'default';
return $this;
}

/**
Expand Down

0 comments on commit f4f3bfe

Please sign in to comment.