Completed
Push — master ( 6ff6d1...70482c )
by Alexey
02:17
created

LogoutAction::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace yiicod\auth\actions\webUser;
4
5
use Yii;
6
use yii\base\Action;
7
use yii\base\Event;
8
use yiicod\auth\actions\ActionEvent;
9
10
/**
11
 * Login action
12
 * @author Orlov Alexey <[email protected]>
13
 */
14
class LogoutAction extends Action
15
{
16
17
    const EVENT_BEFORE_LOGOUT = 'beforeLogout';
18
    const EVENT_AFTER_LOGOUT = 'afterLogout';
19
20
    public $view = '';
21
22
    /**
23
     * Logs out the current user and redirect to homepage.
24
     */
25
    public function run()
26
    {
27
        $this->trigger(static::EVENT_BEFORE_LOGOUT, new ActionEvent($this));
28
29
        Yii::$app->user->logout();
30
31
        $this->trigger(static::EVENT_AFTER_LOGOUT, new ActionEvent($this));
32
33
        return Yii::$app->controller->goHome();
34
    }
35
36
    public function trigger($name, Event $event = null)
37
    {
38
        Yii::$app->trigger(sprintf('yiicod.auth.actions.webUser.LogoutAction.%s', $name), $event);
39
        return parent::trigger($name, $event);
40
    }
41
}
42