mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Replace the get/set methods by only one method in addresses and subject.
This commit is contained in:
parent
f661e37ef1
commit
6e97de5d38
2 changed files with 102 additions and 150 deletions
|
@ -227,97 +227,76 @@ class CakeEmail {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set From
|
||||
* From
|
||||
*
|
||||
* @param mixed $email
|
||||
* @param string $name
|
||||
* @return void
|
||||
* @return mixed
|
||||
* @thrown SocketException
|
||||
*/
|
||||
public function setFrom($email, $name = null) {
|
||||
$this->_setEmail1('_from', $email, $name, __('From requires only 1 email address.'));
|
||||
public function from($email = null, $name = null) {
|
||||
if ($email === null) {
|
||||
return $this->_from;
|
||||
}
|
||||
$this->_setEmailSingle('_from', $email, $name, __('From requires only 1 email address.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the From information
|
||||
*
|
||||
* @return array Key is email, Value is name. If Key is equal of Value, the name is not specified
|
||||
*/
|
||||
public function getFrom() {
|
||||
return $this->_from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Reply-To
|
||||
* Reply-To
|
||||
*
|
||||
* @param mixed $email
|
||||
* @param string $name
|
||||
* @return void
|
||||
* @return mixed
|
||||
* @thrown SocketException
|
||||
*/
|
||||
public function setReplyTo($email, $name = null) {
|
||||
$this->_setEmail1('_replyTo', $email, $name, __('Reply-To requires only 1 email address.'));
|
||||
public function replyTo($email = null, $name = null) {
|
||||
if ($email === null) {
|
||||
return $this->_replyTo;
|
||||
}
|
||||
$this->_setEmailSingle('_replyTo', $email, $name, __('Reply-To requires only 1 email address.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ReplyTo information
|
||||
*
|
||||
* @return array Key is email, Value is name. If Key is equal of Value, the name is not specified
|
||||
*/
|
||||
public function getReplyTo() {
|
||||
return $this->_replyTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Read Receipt (Disposition-Notification-To header)
|
||||
* Read Receipt (Disposition-Notification-To header)
|
||||
*
|
||||
* @param mixed $email
|
||||
* @param string $name
|
||||
* @return void
|
||||
* @return mixed
|
||||
* @thrown SocketException
|
||||
*/
|
||||
public function setReadReceipt($email, $name = null) {
|
||||
$this->_setEmail1('_readReceipt', $email, $name, __('Disposition-Notification-To requires only 1 email address.'));
|
||||
public function readReceipt($email = null, $name = null) {
|
||||
if ($email === null) {
|
||||
return $this->_readReceipt;
|
||||
}
|
||||
$this->_setEmailSingle('_readReceipt', $email, $name, __('Disposition-Notification-To requires only 1 email address.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Read Receipt (Disposition-Notification-To header) information
|
||||
*
|
||||
* @return array Key is email, Value is name. If Key is equal of Value, the name is not specified
|
||||
*/
|
||||
public function getReadReceipt() {
|
||||
return $this->_readReceipt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Return Path
|
||||
* Return Path
|
||||
*
|
||||
* @param mixed $email
|
||||
* @param string $name
|
||||
* @return void
|
||||
* @return mixed
|
||||
* @thrown SocketException
|
||||
*/
|
||||
public function setReturnPath($email, $name = null) {
|
||||
$this->_setEmail1('_returnPath', $email, $name, __('Return-Path requires only 1 email address.'));
|
||||
public function returnPath($email = null, $name = null) {
|
||||
if ($email === null) {
|
||||
return $this->_returnPath;
|
||||
}
|
||||
$this->_setEmailSingle('_returnPath', $email, $name, __('Return-Path requires only 1 email address.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Return Path information
|
||||
* To
|
||||
*
|
||||
* @return array Key is email, Value is name. If Key is equal of Value, the name is not specified
|
||||
*/
|
||||
public function getReturnPath() {
|
||||
return $this->_returnPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set To
|
||||
*
|
||||
* @param mixed $email String with email, Array with email as key, name as value or email as value (without name)
|
||||
* @param mixed $email Null to get, 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 setTo($email, $name = null) {
|
||||
public function to($email = null, $name = null) {
|
||||
if ($email === null) {
|
||||
return $this->_to;
|
||||
}
|
||||
$this->_setEmail('_to', $email, $name);
|
||||
}
|
||||
|
||||
|
@ -333,22 +312,16 @@ class CakeEmail {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get To
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTo() {
|
||||
return $this->_to;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Cc
|
||||
* 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 mixed
|
||||
*/
|
||||
public function setCc($email, $name = null) {
|
||||
public function cc($email = null, $name = null) {
|
||||
if ($email === null) {
|
||||
return $this->_cc;
|
||||
}
|
||||
$this->_setEmail('_cc', $email, $name);
|
||||
}
|
||||
|
||||
|
@ -364,22 +337,16 @@ class CakeEmail {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get Cc
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCc() {
|
||||
return $this->_cc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Bcc
|
||||
* 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
|
||||
*/
|
||||
public function setBcc($email, $name = null) {
|
||||
public function bcc($email = null, $name = null) {
|
||||
if ($email === null) {
|
||||
return $this->_bcc;
|
||||
}
|
||||
$this->_setEmail('_bcc', $email, $name);
|
||||
}
|
||||
|
||||
|
@ -394,15 +361,6 @@ class CakeEmail {
|
|||
$this->_addEmail('_bcc', $email, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Bcc
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBcc() {
|
||||
return $this->_bcc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email
|
||||
*
|
||||
|
@ -446,7 +404,7 @@ class CakeEmail {
|
|||
* @return void
|
||||
* @thrown SocketExpceiton
|
||||
*/
|
||||
protected function _setEmail1($varName, $email, $name, $throwMessage) {
|
||||
protected function _setEmailSingle($varName, $email, $name, $throwMessage) {
|
||||
$current = $this->{$varName};
|
||||
$this->_setEmail($varName, $email, $name);
|
||||
if (count($this->{$varName}) !== 1) {
|
||||
|
@ -491,21 +449,15 @@ class CakeEmail {
|
|||
* Set Subject
|
||||
*
|
||||
* @param string $subject
|
||||
* @return void
|
||||
* @return mixed
|
||||
*/
|
||||
public function setSubject($subject) {
|
||||
public function subject($subject = null) {
|
||||
if ($subject === null) {
|
||||
return $this->_subject;
|
||||
}
|
||||
$this->_subject = (string)$subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Subject
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSubject() {
|
||||
return $this->_subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets headers for the message
|
||||
*
|
||||
|
|
|
@ -124,21 +124,21 @@ class CakeEmailTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testFrom() {
|
||||
$this->assertIdentical($this->CakeEmail->getFrom(), array());
|
||||
$this->assertIdentical($this->CakeEmail->from(), array());
|
||||
|
||||
$this->CakeEmail->setFrom('cake@cakephp.org');
|
||||
$this->CakeEmail->from('cake@cakephp.org');
|
||||
$expected = array('cake@cakephp.org' => 'cake@cakephp.org');
|
||||
$this->assertIdentical($this->CakeEmail->getFrom(), $expected);
|
||||
$this->assertIdentical($this->CakeEmail->from(), $expected);
|
||||
|
||||
$this->CakeEmail->setFrom(array('cake@cakephp.org'));
|
||||
$this->assertIdentical($this->CakeEmail->getFrom(), $expected);
|
||||
$this->CakeEmail->from(array('cake@cakephp.org'));
|
||||
$this->assertIdentical($this->CakeEmail->from(), $expected);
|
||||
|
||||
$this->CakeEmail->setFrom('cake@cakephp.org', 'CakePHP');
|
||||
$this->CakeEmail->from('cake@cakephp.org', 'CakePHP');
|
||||
$expected = array('cake@cakephp.org' => 'CakePHP');
|
||||
$this->assertIdentical($this->CakeEmail->getFrom(), $expected);
|
||||
$this->assertIdentical($this->CakeEmail->from(), $expected);
|
||||
|
||||
$this->CakeEmail->setFrom(array('cake@cakephp.org' => 'CakePHP'));
|
||||
$this->assertIdentical($this->CakeEmail->getFrom(), $expected);
|
||||
$this->CakeEmail->from(array('cake@cakephp.org' => 'CakePHP'));
|
||||
$this->assertIdentical($this->CakeEmail->from(), $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -147,28 +147,28 @@ class CakeEmailTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testTo() {
|
||||
$this->assertIdentical($this->CakeEmail->getTo(), array());
|
||||
$this->assertIdentical($this->CakeEmail->to(), array());
|
||||
|
||||
$this->CakeEmail->setTo('cake@cakephp.org');
|
||||
$this->CakeEmail->to('cake@cakephp.org');
|
||||
$expected = array('cake@cakephp.org' => 'cake@cakephp.org');
|
||||
$this->assertIdentical($this->CakeEmail->getTo(), $expected);
|
||||
$this->assertIdentical($this->CakeEmail->to(), $expected);
|
||||
|
||||
$this->CakeEmail->setTo('cake@cakephp.org', 'CakePHP');
|
||||
$this->CakeEmail->to('cake@cakephp.org', 'CakePHP');
|
||||
$expected = array('cake@cakephp.org' => 'CakePHP');
|
||||
$this->assertIdentical($this->CakeEmail->getTo(), $expected);
|
||||
$this->assertIdentical($this->CakeEmail->to(), $expected);
|
||||
|
||||
$list = array(
|
||||
'cake@cakephp.org' => 'Cake PHP',
|
||||
'cake-php@googlegroups.com' => 'Cake Groups',
|
||||
'root@cakephp.org'
|
||||
);
|
||||
$this->CakeEmail->setTo($list);
|
||||
$this->CakeEmail->to($list);
|
||||
$expected = array(
|
||||
'cake@cakephp.org' => 'Cake PHP',
|
||||
'cake-php@googlegroups.com' => 'Cake Groups',
|
||||
'root@cakephp.org' => 'root@cakephp.org'
|
||||
);
|
||||
$this->assertIdentical($this->CakeEmail->getTo(), $expected);
|
||||
$this->assertIdentical($this->CakeEmail->to(), $expected);
|
||||
|
||||
$this->CakeEmail->addTo('jrbasso@cakephp.org');
|
||||
$this->CakeEmail->addTo('mark_story@cakephp.org', 'Mark Story');
|
||||
|
@ -182,7 +182,7 @@ class CakeEmailTest extends CakeTestCase {
|
|||
'phpnut@cakephp.org' => 'PhpNut',
|
||||
'jose_zap@cakephp.org' => 'jose_zap@cakephp.org'
|
||||
);
|
||||
$this->assertIdentical($this->CakeEmail->getTo(), $expected);
|
||||
$this->assertIdentical($this->CakeEmail->to(), $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -209,7 +209,7 @@ class CakeEmailTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testInvalidEmail($value) {
|
||||
$this->CakeEmail->setTo($value);
|
||||
$this->CakeEmail->to($value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -242,24 +242,24 @@ class CakeEmailTest extends CakeTestCase {
|
|||
*/
|
||||
public function testAddresses() {
|
||||
$this->CakeEmail->reset();
|
||||
$this->CakeEmail->setFrom('cake@cakephp.org', 'CakePHP');
|
||||
$this->CakeEmail->setReplyTo('replyto@cakephp.org', 'ReplyTo CakePHP');
|
||||
$this->CakeEmail->setReadReceipt('readreceipt@cakephp.org', 'ReadReceipt CakePHP');
|
||||
$this->CakeEmail->setReturnPath('returnpath@cakephp.org', 'ReturnPath CakePHP');
|
||||
$this->CakeEmail->setTo('to@cakephp.org', 'To CakePHP');
|
||||
$this->CakeEmail->setCc('cc@cakephp.org', 'Cc CakePHP');
|
||||
$this->CakeEmail->setBcc('bcc@cakephp.org', 'Bcc CakePHP');
|
||||
$this->CakeEmail->from('cake@cakephp.org', 'CakePHP');
|
||||
$this->CakeEmail->replyTo('replyto@cakephp.org', 'ReplyTo CakePHP');
|
||||
$this->CakeEmail->readReceipt('readreceipt@cakephp.org', 'ReadReceipt CakePHP');
|
||||
$this->CakeEmail->returnPath('returnpath@cakephp.org', 'ReturnPath CakePHP');
|
||||
$this->CakeEmail->to('to@cakephp.org', 'To CakePHP');
|
||||
$this->CakeEmail->cc('cc@cakephp.org', 'Cc CakePHP');
|
||||
$this->CakeEmail->bcc('bcc@cakephp.org', 'Bcc CakePHP');
|
||||
$this->CakeEmail->addTo('to2@cakephp.org', 'To2 CakePHP');
|
||||
$this->CakeEmail->addCc('cc2@cakephp.org', 'Cc2 CakePHP');
|
||||
$this->CakeEmail->addBcc('bcc2@cakephp.org', 'Bcc2 CakePHP');
|
||||
|
||||
$this->assertIdentical($this->CakeEmail->getFrom(), array('cake@cakephp.org' => 'CakePHP'));
|
||||
$this->assertIdentical($this->CakeEmail->getReplyTo(), array('replyto@cakephp.org' => 'ReplyTo CakePHP'));
|
||||
$this->assertIdentical($this->CakeEmail->getReadReceipt(), array('readreceipt@cakephp.org' => 'ReadReceipt CakePHP'));
|
||||
$this->assertIdentical($this->CakeEmail->getReturnPath(), array('returnpath@cakephp.org' => 'ReturnPath CakePHP'));
|
||||
$this->assertIdentical($this->CakeEmail->getTo(), array('to@cakephp.org' => 'To CakePHP', 'to2@cakephp.org' => 'To2 CakePHP'));
|
||||
$this->assertIdentical($this->CakeEmail->getCc(), array('cc@cakephp.org' => 'Cc CakePHP', 'cc2@cakephp.org' => 'Cc2 CakePHP'));
|
||||
$this->assertIdentical($this->CakeEmail->getBcc(), array('bcc@cakephp.org' => 'Bcc CakePHP', 'bcc2@cakephp.org' => 'Bcc2 CakePHP'));
|
||||
$this->assertIdentical($this->CakeEmail->from(), array('cake@cakephp.org' => 'CakePHP'));
|
||||
$this->assertIdentical($this->CakeEmail->replyTo(), array('replyto@cakephp.org' => 'ReplyTo CakePHP'));
|
||||
$this->assertIdentical($this->CakeEmail->readReceipt(), array('readreceipt@cakephp.org' => 'ReadReceipt CakePHP'));
|
||||
$this->assertIdentical($this->CakeEmail->returnPath(), array('returnpath@cakephp.org' => 'ReturnPath CakePHP'));
|
||||
$this->assertIdentical($this->CakeEmail->to(), array('to@cakephp.org' => 'To CakePHP', 'to2@cakephp.org' => 'To2 CakePHP'));
|
||||
$this->assertIdentical($this->CakeEmail->cc(), array('cc@cakephp.org' => 'Cc CakePHP', 'cc2@cakephp.org' => 'Cc2 CakePHP'));
|
||||
$this->assertIdentical($this->CakeEmail->bcc(), array('bcc@cakephp.org' => 'Bcc CakePHP', 'bcc2@cakephp.org' => 'Bcc2 CakePHP'));
|
||||
|
||||
$headers = $this->CakeEmail->getHeaders(array_fill_keys(array('from', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'), true));
|
||||
$this->assertIdentical($headers['From'], 'CakePHP <cake@cakephp.org>');
|
||||
|
@ -306,14 +306,14 @@ class CakeEmailTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testSubject() {
|
||||
$this->CakeEmail->setSubject('You have a new message.');
|
||||
$this->assertIdentical($this->CakeEmail->getSubject(), 'You have a new message.');
|
||||
$this->CakeEmail->subject('You have a new message.');
|
||||
$this->assertIdentical($this->CakeEmail->subject(), 'You have a new message.');
|
||||
|
||||
$this->CakeEmail->setSubject(1);
|
||||
$this->assertIdentical($this->CakeEmail->getSubject(), '1');
|
||||
$this->CakeEmail->subject(1);
|
||||
$this->assertIdentical($this->CakeEmail->subject(), '1');
|
||||
|
||||
$this->CakeEmail->setSubject(array('something'));
|
||||
$this->assertIdentical($this->CakeEmail->getSubject(), 'Array');
|
||||
$this->CakeEmail->subject(array('something'));
|
||||
$this->assertIdentical($this->CakeEmail->subject(), 'Array');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -344,7 +344,7 @@ class CakeEmailTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertIdentical($this->CakeEmail->getHeaders(), $expected);
|
||||
|
||||
$this->CakeEmail->setFrom('cake@cakephp.org');
|
||||
$this->CakeEmail->from('cake@cakephp.org');
|
||||
$this->assertIdentical($this->CakeEmail->getHeaders(), $expected);
|
||||
|
||||
$expected = array(
|
||||
|
@ -358,11 +358,11 @@ class CakeEmailTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertIdentical($this->CakeEmail->getHeaders(array('from' => true)), $expected);
|
||||
|
||||
$this->CakeEmail->setFrom('cake@cakephp.org', 'CakePHP');
|
||||
$this->CakeEmail->from('cake@cakephp.org', 'CakePHP');
|
||||
$expected['From'] = 'CakePHP <cake@cakephp.org>';
|
||||
$this->assertIdentical($this->CakeEmail->getHeaders(array('from' => true)), $expected);
|
||||
|
||||
$this->CakeEmail->setTo(array('cake@cakephp.org', 'php@cakephp.org' => 'CakePHP'));
|
||||
$this->CakeEmail->to(array('cake@cakephp.org', 'php@cakephp.org' => 'CakePHP'));
|
||||
$expected = array(
|
||||
'From' => 'CakePHP <cake@cakephp.org>',
|
||||
'To' => 'cake@cakephp.org, CakePHP <php@cakephp.org>',
|
||||
|
@ -412,9 +412,9 @@ class CakeEmailTest extends CakeTestCase {
|
|||
$this->CakeEmail->setTransport('debug');
|
||||
DebugTransport::$includeAddresses = false;
|
||||
|
||||
$this->CakeEmail->setFrom('cake@cakephp.org');
|
||||
$this->CakeEmail->setTo(array('you@cakephp.org' => 'You'));
|
||||
$this->CakeEmail->setSubject('My title');
|
||||
$this->CakeEmail->from('cake@cakephp.org');
|
||||
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
|
||||
$this->CakeEmail->subject('My title');
|
||||
$result = $this->CakeEmail->send("Here is my body, with multi lines.\nThis is the second line.\r\n\r\nAnd the last.");
|
||||
|
||||
$this->assertTrue($result);
|
||||
|
@ -441,9 +441,9 @@ class CakeEmailTest extends CakeTestCase {
|
|||
$this->CakeEmail->setTransport('debug');
|
||||
DebugTransport::$includeAddresses = true;
|
||||
|
||||
$this->CakeEmail->setFrom('cake@cakephp.org');
|
||||
$this->CakeEmail->setTo(array('you@cakephp.org' => 'You'));
|
||||
$this->CakeEmail->setSubject('My title');
|
||||
$this->CakeEmail->from('cake@cakephp.org');
|
||||
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
|
||||
$this->CakeEmail->subject('My title');
|
||||
$this->CakeEmail->setLayout('default', 'default');
|
||||
$result = $this->CakeEmail->send();
|
||||
|
||||
|
@ -458,11 +458,11 @@ class CakeEmailTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testReset() {
|
||||
$this->CakeEmail->setTo('cake@cakephp.org');
|
||||
$this->assertIdentical($this->CakeEmail->getTo(), array('cake@cakephp.org' => 'cake@cakephp.org'));
|
||||
$this->CakeEmail->to('cake@cakephp.org');
|
||||
$this->assertIdentical($this->CakeEmail->to(), array('cake@cakephp.org' => 'cake@cakephp.org'));
|
||||
|
||||
$this->CakeEmail->reset();
|
||||
$this->assertIdentical($this->CakeEmail->getTo(), array());
|
||||
$this->assertIdentical($this->CakeEmail->to(), array());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue