/
View.php
45 lines (36 loc) · 1.13 KB
/
View.php
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
<?php
namespace ShoppingCart;
class View {
public static $controllerName;
public static $actionName;
const PARAMS_COUNT_MODEL_AND_VIEW = 2;
const PARAMS_COUNT_MODEL_ONLY = 1;
const VIEW_FOLDER = 'Views';
const VIEW_EXTENSION = '.php';
public function __construct() {
$params = func_get_args();
if (count($params) == self::PARAMS_COUNT_MODEL_AND_VIEW) {
$view = $params[0];
$model = $params[1];
$this->initModelView($view, $model);
} else {
$model = isset($params[0]) ? $params[0] : null;
$this->initModelOnly($model);
}
}
private function initModelOnly($model) {
require self::VIEW_FOLDER
. DIRECTORY_SEPARATOR
. self::$controllerName
. DIRECTORY_SEPARATOR
. self::$actionName
. self::VIEW_EXTENSION;
}
private function initModelView($view, $model) {
var_dump($view);
require self::VIEW_FOLDER
. DIRECTORY_SEPARATOR
. $view
. self::VIEW_EXTENSION;
}
}