Changed others functions to remove the get/set by only one method.

This commit is contained in:
Juan Basso 2011-03-21 08:30:16 -04:00
parent 6e97de5d38
commit 90d1f62131
2 changed files with 57 additions and 45 deletions

View file

@ -459,7 +459,7 @@ class CakeEmail {
} }
/** /**
* Sets headers for the message * Sets eaders for the message
* *
* @param array Associative array containing headers to be set. * @param array Associative array containing headers to be set.
* @return void * @return void
@ -597,13 +597,19 @@ class CakeEmail {
} }
/** /**
* Set the layout and template * Layout and template
* *
* @param string $layout * @param string $layout
* @param string $template * @param string $template
* @return void * @return mixed
*/ */
public function setLayout($layout, $template = null) { public function layout($layout = null, $template = null) {
if ($layout === null) {
return array(
'layout' => $this->_layout,
'template' => $this->_template
);
}
$this->_layout = (string)$layout; $this->_layout = (string)$layout;
if ($template !== null) { if ($template !== null) {
$this->_template = (string)$template; $this->_template = (string)$template;
@ -611,23 +617,29 @@ class CakeEmail {
} }
/** /**
* Set view class for render * View class for render
* *
* @param string $viewClass * @param string $viewClass
* @return void * @return mixed
*/ */
public function setViewRender($viewClass) { public function viewRender($viewClass = null) {
if ($viewClass === null) {
return $this->_viewRender;
}
$this->_viewRender = $viewClass; $this->_viewRender = $viewClass;
} }
/** /**
* Set the email format * Email format
* *
* @param string $format * @param string $format
* @return void * @return mixed
* @thrown SocketException * @thrown SocketException
*/ */
public function setEmailFormat($format) { public function emailFormat($format = null) {
if ($format === null) {
return $this->_emailFormat;
}
if (!in_array($format, $this->_emailFormatAvailable)) { if (!in_array($format, $this->_emailFormatAvailable)) {
throw new SocketException(__('Format not available.')); throw new SocketException(__('Format not available.'));
} }
@ -635,23 +647,29 @@ class CakeEmail {
} }
/** /**
* Set transport name * Transport name
* *
* @param string $name * @param string $name
* @return void * @return mixed
*/ */
public function setTransport($name) { public function transport($name = null) {
if ($name === null) {
return $this->_transportName;
}
$this->_transportName = (string)$name; $this->_transportName = (string)$name;
} }
/** /**
* Set Message-ID * Message-ID
* *
* @param mixed $message True to generate a new Message-ID, False to ignore (not send in email), String to set as Message-ID * @param mixed $message True to generate a new Message-ID, False to ignore (not send in email), String to set as Message-ID
* @return void * @return mixed
* @thrown SocketException * @thrown SocketException
*/ */
public function setMessageID($message) { public function messageID($message = null) {
if ($message === null) {
return $this->_messageId;
}
if (is_bool($message)) { if (is_bool($message)) {
$this->_messageId = $message; $this->_messageId = $message;
} else { } else {
@ -663,13 +681,16 @@ class CakeEmail {
} }
/** /**
* Set attachments * Attachments
* *
* @param mixed $attachments String with the filename or array with filenames * @param mixed $attachments String with the filename or array with filenames
* @return void * @return mixed
* @thrown SocketException * @thrown SocketException
*/ */
public function setAttachments($attachments) { public function attachments($attachments = null) {
if ($attachments === null) {
return $this->_attachments;
}
$attach = array(); $attach = array();
foreach ((array)$attachments as $name => $file) { foreach ((array)$attachments as $name => $file) {
$path = realpath($file); $path = realpath($file);
@ -693,25 +714,16 @@ class CakeEmail {
*/ */
public function addAttachments($attachments) { public function addAttachments($attachments) {
$current = $this->_attachments; $current = $this->_attachments;
$this->setAttachments($attachments); $this->attachments($attachments);
$this->_attachments = array_merge($current, $this->_attachments); $this->_attachments = array_merge($current, $this->_attachments);
} }
/**
* Get attachments
*
* @return array
*/
public function getAttachments() {
return $this->_attachments;
}
/** /**
* Get generated message (used by transport classes) * Get generated message (used by transport classes)
* *
* @return array * @return array
*/ */
public function getMessage() { public function message() {
return $this->_message; return $this->_message;
} }

View file

@ -76,7 +76,7 @@ class DebugTransport extends AbstractTransport {
* @return boolean * @return boolean
*/ */
public function send(CakeEmail $email) { public function send(CakeEmail $email) {
self::$lastEmail = implode("\r\n", $email->getMessage()); self::$lastEmail = implode("\r\n", $email->message());
$options = array(); $options = array();
if (self::$includeAddresses) { if (self::$includeAddresses) {
$options = array_fill_keys(array('from', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'), true); $options = array_fill_keys(array('from', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'), true);
@ -277,15 +277,15 @@ class CakeEmailTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testMessageId() { public function testMessageId() {
$this->CakeEmail->setMessageId(true); $this->CakeEmail->messageId(true);
$result = $this->CakeEmail->getHeaders(); $result = $this->CakeEmail->getHeaders();
$this->assertTrue(isset($result['Message-ID'])); $this->assertTrue(isset($result['Message-ID']));
$this->CakeEmail->setMessageId(false); $this->CakeEmail->messageId(false);
$result = $this->CakeEmail->getHeaders(); $result = $this->CakeEmail->getHeaders();
$this->assertFalse(isset($result['Message-ID'])); $this->assertFalse(isset($result['Message-ID']));
$this->CakeEmail->setMessageId('<my-email@localhost>'); $this->CakeEmail->messageId('<my-email@localhost>');
$result = $this->CakeEmail->getHeaders(); $result = $this->CakeEmail->getHeaders();
$this->assertIdentical($result['Message-ID'], '<my-email@localhost>'); $this->assertIdentical($result['Message-ID'], '<my-email@localhost>');
} }
@ -297,7 +297,7 @@ class CakeEmailTest extends CakeTestCase {
* @expectedException SocketException * @expectedException SocketException
*/ */
public function testMessageIdInvalid() { public function testMessageIdInvalid() {
$this->CakeEmail->setMessageId('my-email@localhost'); $this->CakeEmail->messageId('my-email@localhost');
} }
/** /**
@ -322,7 +322,7 @@ class CakeEmailTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testHeaders() { public function testHeaders() {
$this->CakeEmail->setMessageId(false); $this->CakeEmail->messageId(false);
$this->CakeEmail->setHeaders(array('X-Something' => 'nice')); $this->CakeEmail->setHeaders(array('X-Something' => 'nice'));
$expected = array( $expected = array(
'X-Something' => 'nice', 'X-Something' => 'nice',
@ -382,14 +382,14 @@ class CakeEmailTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testAttachments() { public function testAttachments() {
$this->CakeEmail->setAttachments(WWW_ROOT . 'index.php'); $this->CakeEmail->attachments(WWW_ROOT . 'index.php');
$expected = array('index.php' => WWW_ROOT . 'index.php'); $expected = array('index.php' => WWW_ROOT . 'index.php');
$this->assertIdentical($this->CakeEmail->getAttachments(), $expected); $this->assertIdentical($this->CakeEmail->attachments(), $expected);
$this->CakeEmail->setAttachments(array()); $this->CakeEmail->attachments(array());
$this->assertIdentical($this->CakeEmail->getAttachments(), array()); $this->assertIdentical($this->CakeEmail->attachments(), array());
$this->CakeEmail->setAttachments(WWW_ROOT . 'index.php'); $this->CakeEmail->attachments(WWW_ROOT . 'index.php');
$this->CakeEmail->addAttachments(WWW_ROOT . 'test.php'); $this->CakeEmail->addAttachments(WWW_ROOT . 'test.php');
$this->CakeEmail->addAttachments(array(WWW_ROOT . 'test.php')); $this->CakeEmail->addAttachments(array(WWW_ROOT . 'test.php'));
$this->CakeEmail->addAttachments(array('other.txt' => WWW_ROOT . 'test.php', 'ht' => WWW_ROOT . '.htaccess')); $this->CakeEmail->addAttachments(array('other.txt' => WWW_ROOT . 'test.php', 'ht' => WWW_ROOT . '.htaccess'));
@ -399,7 +399,7 @@ class CakeEmailTest extends CakeTestCase {
'other.txt' => WWW_ROOT . 'test.php', 'other.txt' => WWW_ROOT . 'test.php',
'ht' => WWW_ROOT . '.htaccess' 'ht' => WWW_ROOT . '.htaccess'
); );
$this->assertIdentical($this->CakeEmail->getAttachments(), $expected); $this->assertIdentical($this->CakeEmail->attachments(), $expected);
} }
/** /**
@ -409,7 +409,7 @@ class CakeEmailTest extends CakeTestCase {
*/ */
public function testSendWithContent() { public function testSendWithContent() {
$this->CakeEmail->reset(); $this->CakeEmail->reset();
$this->CakeEmail->setTransport('debug'); $this->CakeEmail->transport('debug');
DebugTransport::$includeAddresses = false; DebugTransport::$includeAddresses = false;
$this->CakeEmail->from('cake@cakephp.org'); $this->CakeEmail->from('cake@cakephp.org');
@ -438,13 +438,13 @@ class CakeEmailTest extends CakeTestCase {
*/ */
public function testSendRender() { public function testSendRender() {
$this->CakeEmail->reset(); $this->CakeEmail->reset();
$this->CakeEmail->setTransport('debug'); $this->CakeEmail->transport('debug');
DebugTransport::$includeAddresses = true; DebugTransport::$includeAddresses = true;
$this->CakeEmail->from('cake@cakephp.org'); $this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You')); $this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title'); $this->CakeEmail->subject('My title');
$this->CakeEmail->setLayout('default', 'default'); $this->CakeEmail->layout('default', 'default');
$result = $this->CakeEmail->send(); $result = $this->CakeEmail->send();
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'This email was sent using the CakePHP Framework')); $this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'This email was sent using the CakePHP Framework'));