-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathEngineAbstract.php
More file actions
143 lines (128 loc) · 3.33 KB
/
Copy pathEngineAbstract.php
File metadata and controls
143 lines (128 loc) · 3.33 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
declare(strict_types=1);
namespace Bow\View;
use Bow\View\Exception\ViewException;
abstract class EngineAbstract
{
/**
* The helper lists
*
* @var array
*/
protected const HELPERS = [
'secure' => 'secure',
'route' => 'route',
'bow_hash' => 'bow_hash',
'config' => 'config',
'faker' => 'faker',
'env' => 'env',
'app_mode' => 'app_mode',
'app_lang' => 'app_lang',
'flash' => 'flash',
'cache' => 'cache',
'encrypt' => 'encrypt',
'decrypt' => 'decrypt',
'collect' => 'collect',
'url' => 'url',
'input' => 'input',
'response' => 'response',
'request' => 'request',
'sanitize' => 'sanitize',
'slugify' => 'slugify',
'str_slug' => 'str_slug',
'session' => 'session',
'csrf_token' => 'csrf_token',
'csrf_field' => 'csrf_field',
'trans' => 'trans',
't' => 't',
'__' => '__',
'escape' => 'e',
'old' => 'old',
"public_path" => "public_path",
"frontend_path" => "frontend_path",
"storage_path" => "storage_path",
"client_locale" => "client_locale",
"auth" => "auth",
];
/**
* The template engine name
*
* @var string
*/
protected string $name;
/**
* The configuration loader
*
* @var array
*/
protected array $config;
/**
* Make template rendering
*
* @param string $filename
* @param array $data
*
* @return string
*/
abstract public function render(string $filename, array $data = []): string;
/**
* Get the using engine
*
* @return mixed
*/
abstract public function getEngine(): mixed;
/**
* Get the engine name
*
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* Check if the define file exists
*
* @param string $filename
* @return bool
*/
public function fileExists(string $filename): bool
{
$normalized_filename = $this->normalizeFilename($filename);
return file_exists($this->config['path'] . '/' . $normalized_filename);
}
/**
* Normalize the file
*
* @param string $filename
* @return string
*/
private function normalizeFilename(string $filename): string
{
return preg_replace('/@|\./', '/', $filename) . '.' . trim($this->config['extension'], '.');
}
/**
* Check the parsed file
*
* @param string $filename
* @param bool $extended
* @return string
* @throws ViewException
*/
protected function checkParseFile(string $filename, bool $extended = true): string
{
$normalized_filename = $this->normalizeFilename($filename);
// Check if file exists
if ($this->config['path'] !== null && !file_exists($this->config['path'] . '/' . $normalized_filename)) {
throw new ViewException(
sprintf(
'The view [%s] does not exists. %s/%s',
$normalized_filename,
$this->config['path'],
$filename
)
);
}
return $extended ? $normalized_filename : $filename;
}
}