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); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
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); |
||||||
0 ignored issues
–
show
|
|||||||
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())); |
||||||
0 ignored issues
–
show
It seems like
setIndex() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
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); |
||||||
0 ignored issues
–
show
|
|||||||
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())); |
||||||
0 ignored issues
–
show
|
|||||||
86 | break; |
||||||
87 | case '{{TEMPLATE_CLIENT}}': |
||||||
88 | $this->setIndex(str_replace($match, TEMPLATE_CLIENT, $this->getIndex())); |
||||||
0 ignored issues
–
show
|
|||||||
89 | break; |
||||||
90 | case '{{TEMPLATE_DEFAULT}}': |
||||||
91 | $this->setIndex(str_replace($match, TEMPLATE_DEFAULT, $this->getIndex())); |
||||||
0 ignored issues
–
show
|
|||||||
92 | break; |
||||||
93 | case '{{TEMPLATE_DASHBOARD}}': |
||||||
94 | $this->setIndex(str_replace($match, TEMPLATE_DASHBOARD, $this->getIndex())); |
||||||
0 ignored issues
–
show
|
|||||||
95 | break; |
||||||
96 | } |
||||||
97 | } |
||||||
98 | |||||||
99 | } |