1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Inji\View; |
4
|
|
|
|
5
|
|
|
use Inji\App; |
6
|
|
|
use Inji\Controller; |
7
|
|
|
use Inji\Module; |
8
|
|
|
use Inji\Tools; |
9
|
|
|
use Inji\View\Page\Assets; |
10
|
|
|
use Inji\View\Page\Head; |
11
|
|
|
|
12
|
|
|
class Page { |
13
|
|
|
/** |
14
|
|
|
* @var Template |
15
|
|
|
*/ |
16
|
|
|
public $template; |
17
|
|
|
/** |
18
|
|
|
* @var App |
19
|
|
|
*/ |
20
|
|
|
public $app; |
21
|
|
|
/** |
22
|
|
|
* @var Module |
23
|
|
|
*/ |
24
|
|
|
public $module; |
25
|
|
|
/** |
26
|
|
|
* @var Head |
27
|
|
|
*/ |
28
|
|
|
public $head; |
29
|
|
|
/** |
30
|
|
|
* @var Assets |
31
|
|
|
*/ |
32
|
|
|
public $assets; |
33
|
|
|
/** |
34
|
|
|
* @var Content |
35
|
|
|
*/ |
36
|
|
|
public $content; |
37
|
|
|
public $name = ''; |
38
|
|
|
public $path = ''; |
39
|
|
|
public $title = ''; |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
function __construct($params, ?App $app = null) { |
43
|
|
|
$this->app = $app ?? App::$cur; |
44
|
|
|
$this->setParams($params); |
45
|
|
|
$this->head = new Head($this); |
46
|
|
|
$this->assets = new Assets($this); |
47
|
|
|
if (empty($this->template->config['noInjects']) && !empty(\Inji::$config['assets']['js'])) { |
48
|
|
|
foreach (\Inji::$config['assets']['js'] as $js) { |
49
|
|
|
$this->customAsset('js', $js); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function setTitle($title, $add = true) { |
55
|
|
|
if ($add && !empty($this->app->config['site']['name'])) { |
56
|
|
|
if ($title) { |
57
|
|
|
$this->title = $title . ' - ' . $this->app->config['site']['name']; |
58
|
|
|
} else { |
59
|
|
|
$this->title = $this->app->config['site']['name']; |
60
|
|
|
} |
61
|
|
|
} else { |
62
|
|
|
$this->title = $title; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
function setParams($params) { |
|
|
|
|
67
|
|
|
|
68
|
|
|
$this->setTemplate($params['template'] ?? 'default'); |
69
|
|
|
|
70
|
|
|
$this->setPage($params['page'] ?? false); |
71
|
|
|
|
72
|
|
|
$this->setPath($params['pagePath'] ?? false); |
73
|
|
|
|
74
|
|
|
$this->setModule($params['module'] ?? false); |
|
|
|
|
75
|
|
|
|
76
|
|
|
$this->setContent([ |
77
|
|
|
'name' => $params['content'] ?? false, |
78
|
|
|
'path' => $params['contentPath'] ?? false, |
79
|
|
|
'data' => $params['data'] ?? [], |
80
|
|
|
]); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function setContent($content = false) { |
84
|
|
|
if ($content instanceof Content) { |
85
|
|
|
$this->content = $content; |
86
|
|
|
} |
87
|
|
|
if (!$this->content) { |
88
|
|
|
if ($content && is_string($content)) { |
89
|
|
|
$this->content = new Content(['name' => $content], $this); |
90
|
|
|
} elseif ($content && is_array($content)) { |
91
|
|
|
$this->content = new Content($content, $this); |
92
|
|
|
} elseif (Controller::$cur && Controller::$cur->run) { |
93
|
|
|
$this->content = new Content(['name' => Controller::$cur->method], $this); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Set module for content path finder |
100
|
|
|
* |
101
|
|
|
* @param \Inji\Module $module |
102
|
|
|
*/ |
103
|
|
|
public function setModule($module = null) { |
104
|
|
|
if (!$module && !$this->module) { |
105
|
|
|
$this->module = \Inji\Module::$cur; |
106
|
|
|
} else { |
107
|
|
|
$this->module = $module; |
108
|
|
|
} |
109
|
|
|
if (is_string($this->module)) { |
110
|
|
|
$this->module = $this->app->{$this->module}; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function setPath($path = '') { |
115
|
|
|
if ($path) { |
116
|
|
|
$this->path = $path; |
117
|
|
|
} elseif (!$this->path) { |
118
|
|
|
$this->path = Tools::pathsResolve($this->possiblePaths($this->name), false); |
119
|
|
|
} |
120
|
|
|
if (!file_exists($this->path)) { |
121
|
|
|
throw new \Exception('Page path not exist'); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function setPage($pageName = '') { |
126
|
|
|
if ($pageName && $pageName != 'current') { |
127
|
|
|
$this->name = $pageName; |
128
|
|
|
} elseif (!$this->name && !empty($this->app->view->config['defaultPage'])) { |
|
|
|
|
129
|
|
|
$this->name = $this->app->view->config['defaultPage']; |
130
|
|
|
} else { |
131
|
|
|
$this->name = 'index'; |
132
|
|
|
} |
133
|
|
|
return $this->name; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function setTemplate($template) { |
137
|
|
|
if ($template instanceof Template) { |
138
|
|
|
$this->template = $template; |
139
|
|
|
} elseif ($template && is_string($template) && $template != 'current') { |
140
|
|
|
$this->template = Template::get($template, $this->app, $this->app->view->templatesPath()); |
|
|
|
|
141
|
|
|
} else { |
142
|
|
|
$this->template = Template::get('default', $this->app, $this->app->view->templatesPath()); |
143
|
|
|
} |
144
|
|
|
return $this->template; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
function possiblePaths($page) { |
|
|
|
|
148
|
|
|
$paths = [ |
149
|
|
|
'template' => $this->template->path . '/' . $page . '.html' |
150
|
|
|
]; |
151
|
|
|
foreach (\Inji\Module::getModulePaths('View') as $pathName => $path) { |
152
|
|
|
$paths[$pathName] = $path . '/templatePages/' . $page . '.html'; |
153
|
|
|
} |
154
|
|
|
return $paths; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
function send() { |
|
|
|
|
158
|
|
|
App::$cur->log->template_parsed = true; |
|
|
|
|
159
|
|
|
if (file_exists($this->path)) { |
160
|
|
|
$parser = new \Inji\View\Parser\Page($this); |
161
|
|
|
echo $parser->parse(); |
162
|
|
|
} else { |
163
|
|
|
$this->content->draw(); |
|
|
|
|
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.