Completed
Push — master ( b50ff6...0afdf5 )
by Cheren
07:37
created

AppController::beforeRender()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 3
eloc 5
nc 2
nop 1
1
<?php
2
/**
3
 * CakeCMS Core
4
 *
5
 * This file is part of the of the simple cms based on CakePHP 3.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package   Core
10
 * @license   MIT
11
 * @copyright MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link      https://github.com/CakeCMS/Core".
13
 * @author    Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Core\Controller;
17
18
use Core\Plugin;
19
use Cake\Event\Event;
20
use Cake\Network\Response;
21
use Cake\Controller\Controller as CakeController;
22
23
/**
24
 * Class AppController
25
 *
26
 * @package Core\Controller
27
 */
28
class AppController extends CakeController
29
{
30
31
32
    /**
33
     * Initialization hook method.
34
     *
35
     * @return void
36
     */
37
    public function initialize()
38
    {
39
        parent::initialize();
40
        Plugin::manifestEvent('Controller.initialize', $this);
41
    }
42
43
    /**
44
     * Called after the controller action is run, but before the view is rendered. You can use this method
45
     * to perform logic or set view variables that are required on every request.
46
     *
47
     * @param \Cake\Event\Event $event The beforeRender event.
48
     * @return void
49
     */
50
    public function beforeRender(Event $event)
51
    {
52
        Plugin::manifestEvent('Controller.beforeRender', $this, $event);
53
54
        if (!array_key_exists('_serialize', $this->viewVars) &&
55
            in_array($this->response->type(), ['application/json', 'application/xml'])
56
        ) {
57
            $this->set('_serialize', true);
58
        }
59
    }
60
61
    /**
62
     * Called before the controller action. You can use this method to configure and customize components
63
     * or perform logic that needs to happen before each controller action.
64
     *
65
     * @param Event $event
66
     * @return void
67
     */
68
    public function beforeFilter(Event $event)
69
    {
70
        Plugin::manifestEvent('Controller.beforeFilter', $this, $event);
71
    }
72
73
    /**
74
     * The beforeRedirect method is invoked when the controller's redirect method is called but before any
75
     * further action.
76
     *
77
     * @param Event $event
78
     * @param array|string $url
79
     * @param Response $response
80
     * @return void
81
     */
82
    public function beforeRedirect(Event $event, $url, Response $response)
83
    {
84
        Plugin::manifestEvent('Controller.beforeRedirect', $this, $event, $url, $response);
85
    }
86
87
    /**
88
     * Called after the controller action is run and rendered.
89
     *
90
     * @param Event $event
91
     * @return void
92
     */
93
    public function afterFilter(Event $event)
94
    {
95
        Plugin::manifestEvent('Controller.afterFilter', $this, $event);
96
    }
97
}
98