Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
bd8f74cf
Commit
bd8f74cf
authored
Nov 28, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored MessageInterface::send().
parent
eb3b2f45
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
29 deletions
+19
-29
EmailTarget.php
framework/yii/log/EmailTarget.php
+10
-10
BaseMessage.php
framework/yii/mail/BaseMessage.php
+5
-10
MessageInterface.php
framework/yii/mail/MessageInterface.php
+3
-1
BaseMessageTest.php
tests/unit/framework/mail/BaseMessageTest.php
+1
-8
No files found.
framework/yii/log/EmailTarget.php
View file @
bd8f74cf
...
@@ -60,21 +60,21 @@ class EmailTarget extends Target
...
@@ -60,21 +60,21 @@ class EmailTarget extends Target
*/
*/
public
function
export
()
public
function
export
()
{
{
$message
=
$this
->
mail
->
compose
();
$messages
=
array_map
([
$this
,
'formatMessage'
],
$this
->
messages
);
Yii
::
configure
(
$message
,
$this
->
message
);
$body
=
wordwrap
(
implode
(
"
\n
"
,
$messages
),
70
);
$this
->
composeMessage
(
$message
);
$this
->
composeMessage
(
$body
)
->
send
(
$this
->
mail
);
$this
->
mail
->
send
(
$message
);
}
}
/**
/**
* Composes
the given mail message with
body content.
* Composes
a mail message with the given
body content.
*
The default implementation fills the text body of the message with the log messages.
*
@param string $body the body content
* @
param
\yii\mail\MessageInterface $message
* @
return
\yii\mail\MessageInterface $message
*/
*/
protected
function
composeMessage
(
$
message
)
protected
function
composeMessage
(
$
body
)
{
{
$message
s
=
array_map
([
$this
,
'formatMessage'
],
$this
->
messages
);
$message
=
$this
->
mail
->
compose
(
);
$body
=
wordwrap
(
implode
(
"
\n
"
,
$messages
),
70
);
Yii
::
configure
(
$message
,
$this
->
message
);
$message
->
setTextBody
(
$body
);
$message
->
setTextBody
(
$body
);
return
$message
;
}
}
}
}
framework/yii/mail/BaseMessage.php
View file @
bd8f74cf
...
@@ -26,19 +26,14 @@ use Yii;
...
@@ -26,19 +26,14 @@ use Yii;
abstract
class
BaseMessage
extends
Object
implements
MessageInterface
abstract
class
BaseMessage
extends
Object
implements
MessageInterface
{
{
/**
/**
* @return MailerInterface the mailer component
*/
public
function
getMailer
()
{
return
Yii
::
$app
->
getComponent
(
'mail'
);
}
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
send
()
public
function
send
(
MailerInterface
$mailer
=
null
)
{
{
return
$this
->
getMailer
()
->
send
(
$this
);
if
(
$mailer
===
null
)
{
$mailer
=
Yii
::
$app
->
getMail
();
}
return
$mailer
->
send
(
$this
);
}
}
/**
/**
...
...
framework/yii/mail/MessageInterface.php
View file @
bd8f74cf
...
@@ -204,9 +204,11 @@ interface MessageInterface
...
@@ -204,9 +204,11 @@ interface MessageInterface
/**
/**
* Sends this email message.
* Sends this email message.
* @param MailerInterface $mailer the mailer that should be used to send this message.
* If null, the "mail" application component will be used instead.
* @return boolean whether this message is sent successfully.
* @return boolean whether this message is sent successfully.
*/
*/
public
function
send
();
public
function
send
(
MailerInterface
$mailer
=
null
);
/**
/**
* Returns string representation of this message.
* Returns string representation of this message.
...
...
tests/unit/framework/mail/BaseMessageTest.php
View file @
bd8f74cf
...
@@ -40,18 +40,11 @@ class BaseMessageTest extends TestCase
...
@@ -40,18 +40,11 @@ class BaseMessageTest extends TestCase
// Tests :
// Tests :
public
function
testGetMailer
()
{
$mailer
=
$this
->
getMailer
();
$message
=
$mailer
->
compose
();
$this
->
assertEquals
(
$mailer
,
$message
->
getMailer
());
}
public
function
testSend
()
public
function
testSend
()
{
{
$mailer
=
$this
->
getMailer
();
$mailer
=
$this
->
getMailer
();
$message
=
$mailer
->
compose
();
$message
=
$mailer
->
compose
();
$message
->
send
();
$message
->
send
(
$mailer
);
$this
->
assertEquals
(
$message
,
$mailer
->
sentMessages
[
0
],
'Unable to send message!'
);
$this
->
assertEquals
(
$message
,
$mailer
->
sentMessages
[
0
],
'Unable to send message!'
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment