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
368c2447
Commit
368c2447
authored
Nov 04, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MessageInterface::render() replaced by MessageInterface::renderHtml() and…
MessageInterface::render() replaced by MessageInterface::renderHtml() and MessageInterface::renderText()
parent
4c27d887
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
15 deletions
+74
-15
BaseMailer.php
framework/yii/mail/BaseMailer.php
+17
-4
BaseMessage.php
framework/yii/mail/BaseMessage.php
+14
-3
MessageInterface.php
framework/yii/mail/MessageInterface.php
+16
-5
BaseMailerTest.php
tests/unit/framework/mail/BaseMailerTest.php
+27
-3
No files found.
framework/yii/mail/BaseMailer.php
View file @
368c2447
...
...
@@ -20,7 +20,6 @@ use yii\base\ViewContextInterface;
* @see BaseMessage
*
* @property \yii\base\View|array $view view instance or its array configuration.
* @property \yii\mail\ViewResolver|array $viewResolver view resolver instance or its array configuration.
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
...
...
@@ -36,6 +35,14 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
*/
public
$viewPath
=
'@app/mailviews'
;
/**
* @var string HTML layout view name.
*/
public
$htmlLayout
=
'layouts/html'
;
/**
* @var string text layout view name.
*/
public
$textLayout
=
'layouts/text'
;
/**
* @var array configuration, which should be applied by default to any new created
* email message instance.
* For example:
...
...
@@ -128,11 +135,17 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
* Renders a view.
* @param string $view the view name or the path alias of the view file.
* @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
* @return string string the rendering result
* @param string|boolean $layout layout view name, if false given no layout will be applied.
* @return string the rendering result.
*/
public
function
render
(
$view
,
$params
=
[])
public
function
render
(
$view
,
$params
=
[]
,
$layout
=
false
)
{
return
$this
->
getView
()
->
render
(
$view
,
$params
,
$this
);
$output
=
$this
->
getView
()
->
render
(
$view
,
$params
,
$this
);
if
(
$layout
!==
false
)
{
return
$this
->
getView
()
->
render
(
$layout
,
[
'content'
=>
$output
],
$this
);
}
else
{
return
$output
;
}
}
/**
...
...
framework/yii/mail/BaseMessage.php
View file @
368c2447
...
...
@@ -36,7 +36,7 @@ use Yii;
abstract
class
BaseMessage
extends
Object
implements
MessageInterface
{
/**
* @return \yii\mail\BaseMailer
* @return \yii\mail\BaseMailer
mailer component instance.
*/
public
function
getMailer
()
{
...
...
@@ -54,8 +54,18 @@ abstract class BaseMessage extends Object implements MessageInterface
/**
* @inheritdoc
*/
public
function
render
(
$view
,
$params
=
[])
public
function
render
Html
(
$view
,
$params
=
[])
{
return
$this
->
getMailer
()
->
render
(
$view
,
$params
);
$this
->
setHtml
(
$this
->
render
(
$view
,
$params
,
$this
->
getMailer
()
->
htmlLayout
));
return
$this
;
}
/**
* @inheritdoc
*/
public
function
renderText
(
$view
,
$params
=
[])
{
$this
->
setText
(
$this
->
render
(
$view
,
$params
,
$this
->
getMailer
()
->
textLayout
));
return
$this
;
}
}
\ No newline at end of file
framework/yii/mail/MessageInterface.php
View file @
368c2447
...
...
@@ -122,15 +122,26 @@ interface MessageInterface
public
function
send
();
/**
*
Renders
a view.
*
Fills up HTML body rendering
a view.
* The view to be rendered can be specified in one of the following formats:
* - path alias (e.g. "@app/
e
mails/contact/body");
* - relative path (e.g. "contact"): the actual view file will be resolved by [[
resolveView
]].
* - path alias (e.g. "@app/mails/contact/body");
* - relative path (e.g. "contact"): the actual view file will be resolved by [[
\yii\base\ViewContextInterface
]].
* @param string $view the view name or the path alias of the view file.
* @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
* @return st
ring string the rendering result
* @return st
atic self reference.
*/
public
function
render
(
$view
,
$params
=
[]);
public
function
renderHtml
(
$view
,
$params
=
[]);
/**
* Fills up plain text body rendering a view.
* The view to be rendered can be specified in one of the following formats:
* - path alias (e.g. "@app/mails/contact/body");
* - relative path (e.g. "contact"): the actual view file will be resolved by [[\yii\base\ViewContextInterface]].
* @param string $view the view name or the path alias of the view file.
* @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
* @return static self reference.
*/
public
function
renderText
(
$view
,
$params
=
[]);
/**
* String output.
...
...
tests/unit/framework/mail/BaseMailerTest.php
View file @
368c2447
...
...
@@ -134,9 +134,9 @@ class BaseMailerTest extends TestCase
$mailer
->
viewPath
=
$filePath
;
$viewName
=
'test_view'
;
$
f
ileName
=
$filePath
.
DIRECTORY_SEPARATOR
.
$viewName
.
'.php'
;
$
f
ileContent
=
'<?php echo $testParam; ?>'
;
file_put_contents
(
$
fileName
,
$f
ileContent
);
$
viewF
ileName
=
$filePath
.
DIRECTORY_SEPARATOR
.
$viewName
.
'.php'
;
$
viewF
ileContent
=
'<?php echo $testParam; ?>'
;
file_put_contents
(
$
viewFileName
,
$viewF
ileContent
);
$params
=
[
'testParam'
=>
'test output'
...
...
@@ -144,6 +144,30 @@ class BaseMailerTest extends TestCase
$renderResult
=
$mailer
->
render
(
$viewName
,
$params
);
$this
->
assertEquals
(
$params
[
'testParam'
],
$renderResult
);
}
/**
* @depends testRender
*/
public
function
testRenderLayout
()
{
$mailer
=
new
Mailer
();
$filePath
=
$this
->
getTestFilePath
();
$mailer
->
viewPath
=
$filePath
;
$viewName
=
'test_view'
;
$viewFileName
=
$filePath
.
DIRECTORY_SEPARATOR
.
$viewName
.
'.php'
;
$viewFileContent
=
'view file content'
;
file_put_contents
(
$viewFileName
,
$viewFileContent
);
$layoutName
=
'test_layout'
;
$layoutFileName
=
$filePath
.
DIRECTORY_SEPARATOR
.
$layoutName
.
'.php'
;
$layoutFileContent
=
'Begin Layout <?php echo $content; ?> End Layout'
;
file_put_contents
(
$layoutFileName
,
$layoutFileContent
);
$renderResult
=
$mailer
->
render
(
$viewName
,
[],
$layoutName
);
$this
->
assertEquals
(
'Begin Layout '
.
$viewFileContent
.
' End Layout'
,
$renderResult
);
}
}
/**
...
...
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