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
c0316a10
Commit
c0316a10
authored
Dec 29, 2013
by
Mark
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added mail events before/after send
parent
3577b5c9
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
92 additions
and
21 deletions
+92
-21
ActionEvent.php
framework/yii/base/ActionEvent.php
+4
-7
Event.php
framework/yii/base/Event.php
+5
-0
MailEvent.php
framework/yii/base/MailEvent.php
+30
-0
ModelEvent.php
framework/yii/base/ModelEvent.php
+2
-6
ViewEvent.php
framework/yii/base/ViewEvent.php
+5
-6
BaseMailer.php
framework/yii/mail/BaseMailer.php
+46
-2
No files found.
framework/yii/base/ActionEvent.php
View file @
c0316a10
...
@@ -11,7 +11,10 @@ namespace yii\base;
...
@@ -11,7 +11,10 @@ namespace yii\base;
* ActionEvent represents the event parameter used for an action event.
* ActionEvent represents the event parameter used for an action event.
*
*
* By setting the [[isValid]] property, one may control whether to continue running the action.
* By setting the [[isValid]] property, one may control whether to continue running the action.
*
* @property boolean $isValid Event handlers of
* [[Controller::EVENT_BEFORE_ACTION]] may set this property to decide whether
* to continue running the current action.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @since 2.0
*/
*/
...
@@ -25,12 +28,6 @@ class ActionEvent extends Event
...
@@ -25,12 +28,6 @@ class ActionEvent extends Event
* @var mixed the action result. Event handlers may modify this property to change the action result.
* @var mixed the action result. Event handlers may modify this property to change the action result.
*/
*/
public
$result
;
public
$result
;
/**
* @var boolean whether to continue running the action. Event handlers of
* [[Controller::EVENT_BEFORE_ACTION]] may set this property to decide whether
* to continue running the current action.
*/
public
$isValid
=
true
;
/**
/**
* Constructor.
* Constructor.
...
...
framework/yii/base/Event.php
View file @
c0316a10
...
@@ -46,6 +46,11 @@ class Event extends Object
...
@@ -46,6 +46,11 @@ class Event extends Object
*/
*/
public
$data
;
public
$data
;
/**
* @var boolean whether to continue execution of process or not.
*/
public
$isValid
=
true
;
private
static
$_events
=
[];
private
static
$_events
=
[];
/**
/**
...
...
framework/yii/base/MailEvent.php
0 → 100644
View file @
c0316a10
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\base
;
/**
* ActionEvent represents the event parameter used for an action event.
*
* By setting the [[isValid]] property, one may control whether to continue running the action.
*
* @author Mark Jebri <mark.github@yandex.ru>
* @since 2.0
*/
class
MailEvent
extends
Event
{
/**
* @var \yii\mail\MessageInterface mail message being send
*/
public
$message
;
/**
*
*/
public
$isSuccessful
;
}
framework/yii/base/ModelEvent.php
View file @
c0316a10
...
@@ -11,15 +11,11 @@ namespace yii\base;
...
@@ -11,15 +11,11 @@ namespace yii\base;
* ModelEvent class.
* ModelEvent class.
*
*
* ModelEvent represents the parameter needed by model events.
* ModelEvent represents the parameter needed by model events.
*
* @property boolean $isValid A model is in valid status if it passes validations or certain checks.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @since 2.0
*/
*/
class
ModelEvent
extends
Event
class
ModelEvent
extends
Event
{
{
/**
* @var boolean whether the model is in valid status. Defaults to true.
* A model is in valid status if it passes validations or certain checks.
*/
public
$isValid
=
true
;
}
}
framework/yii/base/ViewEvent.php
View file @
c0316a10
...
@@ -10,6 +10,11 @@ namespace yii\base;
...
@@ -10,6 +10,11 @@ namespace yii\base;
/**
/**
* ViewEvent represents events triggered by the [[View]] component.
* ViewEvent represents events triggered by the [[View]] component.
*
*
* @property boolean $isValid whether to continue rendering the view file. Event handlers of
*[[View::EVENT_BEFORE_RENDER]] may set this property to decide whether
* to continue rendering the current view file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @since 2.0
*/
*/
...
@@ -26,12 +31,6 @@ class ViewEvent extends Event
...
@@ -26,12 +31,6 @@ class ViewEvent extends Event
* @var string the view file path that is being rendered by [[View::renderFile()]].
* @var string the view file path that is being rendered by [[View::renderFile()]].
*/
*/
public
$viewFile
;
public
$viewFile
;
/**
* @var boolean whether to continue rendering the view file. Event handlers of
* [[View::EVENT_BEFORE_RENDER]] may set this property to decide whether
* to continue rendering the current view file.
*/
public
$isValid
=
true
;
/**
/**
* Constructor.
* Constructor.
...
...
framework/yii/mail/BaseMailer.php
View file @
c0316a10
...
@@ -12,6 +12,7 @@ use yii\base\Component;
...
@@ -12,6 +12,7 @@ use yii\base\Component;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidConfigException
;
use
yii\base\ViewContextInterface
;
use
yii\base\ViewContextInterface
;
use
yii\web\View
;
use
yii\web\View
;
use
yii\base\MailEvent
;
/**
/**
* BaseMailer serves as a base class that implements the basic functions required by [[MailerInterface]].
* BaseMailer serves as a base class that implements the basic functions required by [[MailerInterface]].
...
@@ -28,6 +29,16 @@ use yii\web\View;
...
@@ -28,6 +29,16 @@ use yii\web\View;
*/
*/
abstract
class
BaseMailer
extends
Component
implements
MailerInterface
,
ViewContextInterface
abstract
class
BaseMailer
extends
Component
implements
MailerInterface
,
ViewContextInterface
{
{
/**
* @event ActionEvent an event raised right before executing a controller action.
* You may set [[ActionEvent::isValid]] to be false to cancel the action execution.
*/
const
EVENT_BEFORE_SEND
=
'beforeSend'
;
/**
* @event ActionEvent an event raised right after executing a controller action.
*/
const
EVENT_AFTER_SEND
=
'afterSend'
;
/**
/**
* @var string directory containing view files for this email messages.
* @var string directory containing view files for this email messages.
* This can be specified as an absolute path or path alias.
* This can be specified as an absolute path or path alias.
...
@@ -206,6 +217,10 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
...
@@ -206,6 +217,10 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
*/
*/
public
function
send
(
$message
)
public
function
send
(
$message
)
{
{
if
(
!
$this
->
beforeSend
(
$message
))
{
return
false
;
}
$address
=
$message
->
getTo
();
$address
=
$message
->
getTo
();
if
(
is_array
(
$address
))
{
if
(
is_array
(
$address
))
{
$address
=
implode
(
', '
,
array_keys
(
$address
));
$address
=
implode
(
', '
,
array_keys
(
$address
));
...
@@ -213,10 +228,12 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
...
@@ -213,10 +228,12 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
Yii
::
info
(
'Sending email "'
.
$message
->
getSubject
()
.
'" to "'
.
$address
.
'"'
,
__METHOD__
);
Yii
::
info
(
'Sending email "'
.
$message
->
getSubject
()
.
'" to "'
.
$address
.
'"'
,
__METHOD__
);
if
(
$this
->
useFileTransport
)
{
if
(
$this
->
useFileTransport
)
{
return
$this
->
saveMessage
(
$message
);
$isSuccessful
=
$this
->
saveMessage
(
$message
);
}
else
{
}
else
{
return
$this
->
sendMessage
(
$message
);
$isSuccessful
=
$this
->
sendMessage
(
$message
);
}
}
$this
->
afterSend
(
$message
,
$isSuccessful
);
return
$isSuccessful
;
}
}
/**
/**
...
@@ -297,4 +314,31 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
...
@@ -297,4 +314,31 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
{
{
return
Yii
::
getAlias
(
$this
->
viewPath
)
.
DIRECTORY_SEPARATOR
.
$view
;
return
Yii
::
getAlias
(
$this
->
viewPath
)
.
DIRECTORY_SEPARATOR
.
$view
;
}
}
/**
* This method is invoked right before mail send.
* You may override this method to do last-minute preparation for the message.
* If you override this method, please make sure you call the parent implementation first.
* @param MessageInterface $message
*/
public
function
beforeSend
(
$message
)
{
$event
=
new
MailEvent
([
'message'
=>
$message
]);
$this
->
trigger
(
self
::
EVENT_BEFORE_SEND
,
$event
);
return
$event
->
isValid
;
}
/**
* This method is invoked right after mail was send.
* You may override this method to do some postprocessing or logging based on mail send status.
* If you override this method, please make sure you call the parent implementation first.
* @param MessageInterface $message
* @param boolean $isSuccessful
*/
public
function
afterSend
(
$message
,
$isSuccessful
)
{
$event
=
new
MailEvent
([
'message'
=>
$message
,
'isSuccessful'
=>
$isSuccessful
]);
$this
->
trigger
(
self
::
EVENT_AFTER_SEND
,
$event
);
}
}
}
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