-
Notifications
You must be signed in to change notification settings - Fork 1
/
MPage.php
63 lines (53 loc) · 1.65 KB
/
MPage.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace Orkester\UI;
use Orkester\Manager;
class MPage
{
private string $templatePath;
private string $templateName;
private string $content;
private MBlade $template;
public function __construct()
{
$this->templatePath = Manager::getConf('template.path');
$this->templateName = Manager::getConf('template.index');
$path = Manager::getBasePath("public/{$this->templatePath}");
$this->template = new MBlade([$path]);
}
public function getTemplate()
{
return $this->template;
}
public function fetch($templateName = '')
{
$args['page'] = $this;
return ($templateName == '') ? $this->template->fetch($this->templateName, $args) : $this->template->fetch($templateName, $args);
}
public function renderContent()
{
return $this->content;
}
public function renderView(string $view, bool $fragment = false)
{
$viewPath = Manager::getAppPath("UI/Views/{$view}");
$path = dirname($viewPath);
$view = basename($viewPath);
$template = new MBlade([$path]);
$this->content = $template->fetch($view);
return $this->content;
}
public function renderInertia(object $inertia)
{
$page = htmlspecialchars(
json_encode($inertia),
ENT_QUOTES,
'UTF-8',
true
);
$this->content = "<div id=\"app\" class=\"fit\" data-page=\"{$page}\"></div>";
$args = [
'component' => $inertia->component
];
return $this->fetch('', $args);
}
}