-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathwaViewController.class.php
More file actions
121 lines (106 loc) · 2.73 KB
/
Copy pathwaViewController.class.php
File metadata and controls
121 lines (106 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/*
* This file is part of Webasyst framework.
*
* Licensed under the terms of the GNU Lesser General Public License (LGPL).
* http://www.webasyst.com/framework/license/
*
* @link http://www.webasyst.com/
* @author Webasyst LLC
* @copyright 2011 Webasyst LLC
* @package wa-system
* @subpackage controller
*/
abstract class waViewController extends waController
{
/**
* @var waLayout
*/
protected $layout = null;
protected $blocks = array();
public function __construct()
{
}
/**
* Set layout
*
* @param waLayout $layout
*/
public function setLayout(?waLayout $layout=null)
{
$this->layout = $layout;
}
/**
* Execute controller and display result
*
* @see waController::run()
*/
public function run($params = null)
{
parent::run($params);
$this->display();
}
protected function preExecute()
{
wa()->getUser()->updateLastPage();
}
public function execute()
{
}
/**
* Return layout or null
*
* @return waLayout|null
*/
public function getLayout()
{
if ($this->layout instanceof waLayout) {
return $this->layout;
}
return null;
}
/**
* Execute action $action and save result to array $this->blocks
*
* @param waViewAction $action
* @param waDecorator $decorator
* @param string $name
*/
public function executeAction(waViewAction $action, $name = 'content', ?waDecorator $decorator = null)
{
$action->setController($this);
if ($action->getLayout()) {
$this->setLayout($action->getLayout());
}
$content = $decorator ? $decorator->display($action) : $action->display();
if (isset($this->blocks[$name])) {
$this->blocks[$name] .= $content;
} else {
$this->blocks[$name] = $content;
}
}
/**
* Display result
*/
public function display()
{
if ($this->layout instanceof waLayout) {
foreach ($this->blocks as $name => $content) {
$this->layout->setBlock($name, $content);
}
$this->layout->display();
} else {
if ((wa()->getEnv() == 'frontend') && waRequest::param('theme_mobile') &&
(waRequest::param('theme') != waRequest::param('theme_mobile'))) {
wa()->getResponse()->addHeader('Vary', 'User-Agent');
}
// Send headers
waSystem::getInstance()->getResponse()->sendHeaders();
// Print all blocks
foreach ($this->blocks as $content) {
echo $content;
}
}
}
}
// EOF