1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Erykai\Template; |
4
|
|
|
|
5
|
|
|
use stdClass; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* TraitTemplate |
9
|
|
|
*/ |
10
|
|
|
trait TraitTemplate |
11
|
|
|
{ |
12
|
|
|
abstract public function getIndex(): string; |
13
|
|
|
abstract public function getMenu(): ?string; |
14
|
|
|
abstract protected function getPage(): string; |
15
|
|
|
/** |
16
|
|
|
* navigation |
17
|
|
|
*/ |
18
|
|
|
protected function page(): void |
19
|
|
|
{ |
20
|
|
|
preg_match_all(TEMPLATE_REGEX_GLOBAL, $this->getIndex(), $matches); |
|
|
|
|
21
|
|
|
foreach ($matches[0] as $match) { |
22
|
|
|
$this->globals($match); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
preg_match_all(TEMPLATE_REGEX_GLOBAL, $this->getMenu(), $matches); |
26
|
|
|
foreach ($matches[0] as $match) { |
27
|
|
|
$this->globals($match); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
preg_match_all(TEMPLATE_REGEX_GLOBAL, $this->getPage(), $page); |
31
|
|
|
|
32
|
|
|
foreach ($page[0] as $match) { |
33
|
|
|
$this->globals($match); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
/** |
37
|
|
|
* translate links {{#/dashboard#}} |
38
|
|
|
*/ |
39
|
|
|
protected function route(): void |
40
|
|
|
{ |
41
|
|
|
preg_match_all(TEMPLATE_REGEX_ROUTE, $this->getIndex(), $matches); |
|
|
|
|
42
|
|
|
foreach ($matches[0] as $key => $match) { |
43
|
|
|
$route = str_replace(['{{#', '#}}'], "", $matches[0][$key]); |
44
|
|
|
$data = new stdClass(); |
45
|
|
|
$data->file = 'route'; |
46
|
|
|
$data->text = $route; |
47
|
|
|
$text = $this->translate->data( $data)->target()->response(); |
48
|
|
|
$this->setIndex(str_replace($matches[0][$key], $text->translate, $this->getIndex())); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
/** |
52
|
|
|
* @param $fileTranslator |
53
|
|
|
* translate text {{Hello world}} |
54
|
|
|
*/ |
55
|
|
|
protected function text($fileTranslator, string $module = null): void |
56
|
|
|
{ |
57
|
|
|
preg_match_all(TEMPLATE_REGEX_TEXT, $this->getIndex(), $matches); |
|
|
|
|
58
|
|
|
|
59
|
|
|
foreach ($matches[0] as $key => $match) { |
60
|
|
|
$data = new stdClass(); |
61
|
|
|
$data->file = $fileTranslator; |
62
|
|
|
$data->text = $matches[1][$key]; |
63
|
|
|
$text = $this->translate->data($data)->target(null, $module)->response(); |
64
|
|
|
$this->setIndex(str_replace($matches[0][$key], $text->translate, $this->getIndex())); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $match |
71
|
|
|
*/ |
72
|
|
|
private function globals(string $match): void |
73
|
|
|
{ |
74
|
|
|
switch ($match) { |
75
|
|
|
case '{{PAGE}}': |
76
|
|
|
$this->setIndex(str_replace($match, $this->getPage(), $this->getIndex())); |
77
|
|
|
break; |
78
|
|
|
case '{{MENU}}': |
79
|
|
|
$this->setIndex(str_replace($match, $this->getMenu(), $this->getIndex())); |
80
|
|
|
break; |
81
|
|
|
case '{{LANG}}': |
82
|
|
|
$this->setIndex(str_replace($match, $this->translate->lang(), $this->getIndex())); |
83
|
|
|
break; |
84
|
|
|
case '{{TEMPLATE_URL}}': |
85
|
|
|
$this->setIndex(str_replace($match, TEMPLATE_URL, $this->getIndex())); |
|
|
|
|
86
|
|
|
break; |
87
|
|
|
case '{{TEMPLATE_CLIENT}}': |
88
|
|
|
$this->setIndex(str_replace($match, TEMPLATE_CLIENT, $this->getIndex())); |
|
|
|
|
89
|
|
|
break; |
90
|
|
|
case '{{TEMPLATE_DEFAULT}}': |
91
|
|
|
$this->setIndex(str_replace($match, TEMPLATE_DEFAULT, $this->getIndex())); |
|
|
|
|
92
|
|
|
break; |
93
|
|
|
case '{{TEMPLATE_DASHBOARD}}': |
94
|
|
|
$this->setIndex(str_replace($match, TEMPLATE_DASHBOARD, $this->getIndex())); |
|
|
|
|
95
|
|
|
break; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
} |