-
Notifications
You must be signed in to change notification settings - Fork 1
/
Constants.php
152 lines (134 loc) · 3.15 KB
/
Constants.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
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
144
145
146
147
148
149
150
151
152
<?php
namespace Neoan3\Apps\Template;
/**
*
*/
class Constants
{
/**
* @var array
*/
private static array $customAttributes = [];
/**
* @var string
*/
private static string $encoding = 'utf-8';
/**
* @var array
*/
private static array $customFunctions = [];
/**
* @var array|string[]
*/
private static array $delimiter = ['{{','}}'];
/**
* @var string
*/
private static string $path;
/**
* @return string
*/
public static function getPath(): string
{
if(!isset(self::$path)){
self::$path = dirname(__DIR__,3);
}
return self::$path;
}
/**
* @return array
*/
public static function getCustomAttributes(): array
{
return self::$customAttributes;
}
/**
* @return string
*/
public static function getEncoding(): string
{
return self::$encoding;
}
/**
* @return array
*/
public static function getCustomFunctions(): array
{
return self::$customFunctions;
}
/**
* @return array
*/
public static function getDelimiter(): array
{
return [...self::$delimiter, urlencode(self::$delimiter[0]), urlencode(self::$delimiter[1])];
}
public static function delimiterIsTag(): bool
{
return preg_match('/^<([^>]+)>$/',self::$delimiter[0]) === 1;
}
/**
* @param string $key
* @param callable $attributeInstance
* @return void
*/
public static function addCustomAttribute(string $key, callable $attributeInstance): void
{
self::$customAttributes[$key] = $attributeInstance;
}
/**
* @param string $encoding
*/
public static function setEncoding(string $encoding): void
{
self::$encoding = $encoding;
}
/**
* @param string $key
* @param callable $customFunction
* @return void
*/
public static function addCustomFunction(string $key, callable $customFunction): void
{
self::$customFunctions[$key] = $customFunction;
}
/**
* @param string $start
* @param string $end
* @return void
*/
public static function setDelimiter(string $start = '{{', string $end = '}}'): void
{
self::$delimiter = [$start, $end];
}
/**
* @param string $path
* @return void
*/
public static function setPath(string $path): void
{
self::$path = $path;
}
/**
* @param iterable $data
* @param string|null $parentKey
* @return array
*/
public static function flattenArray(iterable $data, string $parentKey = null): array
{
$answer = [];
foreach ($data as $key => $value) {
if ($parentKey) {
$key = $parentKey . '.' . $key;
}
if (!is_array($value)) {
$answer[$key] = $value;
} else {
$answer[$key] = 'Array';
$answer[$key.'.length'] = sizeof($value);
$answer = array_merge($answer, self::flattenArray($value, $key));
}
}
return $answer;
}
}