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.
* @return void
@ -597,13 +597,19 @@ class CakeEmail {
}
/**
* Set the layout and template
* Layout and template
*
* @param string $layout
* @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;
if ($template !== null) {
$this->_template = (string)$template;
@ -611,23 +617,29 @@ class CakeEmail {
}
/**
* Set view class for render
* View class for render
*
* @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;
}
/**
* Set the email format
* Email format
*
* @param string $format
* @return void
* @return mixed
* @thrown SocketException
*/
public function setEmailFormat($format) {
public function emailFormat($format = null) {
if ($format === null) {
return $this->_emailFormat;
}
if (!in_array($format, $this->_emailFormatAvailable)) {
throw new SocketException(__('Format not available.'));
}
@ -635,23 +647,29 @@ class CakeEmail {
}
/**
* Set transport name
* Transport 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;
}
/**
* 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
* @return void
* @return mixed
* @thrown SocketException
*/
public function setMessageID($message) {
public function messageID($message = null) {
if ($message === null) {
return $this->_messageId;
}
if (is_bool($message)) {
$this->_messageId = $message;
} else {
@ -663,13 +681,16 @@ class CakeEmail {
}
/**
* Set attachments
* Attachments
*
* @param mixed $attachments String with the filename or array with filenames
* @return void
* @return mixed
* @thrown SocketException
*/
public function setAttachments($attachments) {
public function attachments($attachments = null) {
if ($attachments === null) {
return $this->_attachments;
}
$attach = array();
foreach ((array)$attachments as $name => $file) {
$path = realpath($file);
@ -693,25 +714,16 @@ class CakeEmail {
*/
public function addAttachments($attachments) {
$current = $this->_attachments;
$this->setAttachments($attachments);
$this->attachments($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)
*
* @return array
*/
public function getMessage() {
public function message() {
return $this->_message;
}

View file

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