1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if (!function_exists('get_user_timezone')) { |
4
|
|
|
function get_user_timezone() |
|
|
|
|
5
|
|
|
{ |
6
|
|
|
return 'UTC'; |
7
|
|
|
} |
8
|
|
|
} |
9
|
|
|
|
10
|
|
|
if (!function_exists('get_request_ip')) { |
11
|
|
|
function get_request_ip() |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
if (isset($_SERVER['X_FORWARDED_FOR'])) { |
14
|
|
|
return $_SERVER['X_FORWARDED_FOR']; |
15
|
|
|
} elseif (isset($_SERVER['CLIENT_IP'])) { |
16
|
|
|
return $_SERVER['CLIENT_IP']; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
return $_SERVER['REMOTE_ADDR']; |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
if (!function_exists('to_name_value')) { |
25
|
|
|
function to_name_value($array, $keys = null) |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$data = []; |
28
|
|
|
foreach ($array as $name => $value) { |
29
|
|
|
$row = ['name' => $name, 'value' => $value]; |
30
|
|
|
if (isset($keys)) $row = array_merge($row, $keys); |
31
|
|
|
array_push($data, $row); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return $data; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if (!function_exists('sorting_by_key')) { |
39
|
|
|
/** |
40
|
|
|
* Sorting callable helper |
41
|
|
|
* |
42
|
|
|
* @param string $key |
43
|
|
|
* @param string $order |
44
|
|
|
* |
45
|
|
|
* @return Closure |
46
|
|
|
*/ |
47
|
|
|
function sorting_by_key($key, $order = 'ASC') |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
return function ($a, $b) use ($key, $order) { |
50
|
|
|
if ($a[$key] === $b[$key]) { |
51
|
|
|
return 0; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$value = $a[$key] < $b[$key] ? -1 : 1; |
55
|
|
|
if ($order === 'DESC') { |
56
|
|
|
$value *= -1; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $value; |
60
|
|
|
}; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if (!function_exists('get_columns_flat_at')) { |
65
|
|
|
/** |
66
|
|
|
* Get all the columns name in the given level |
67
|
|
|
* |
68
|
|
|
* @param array $columns |
69
|
|
|
* @param int $level |
70
|
|
|
* |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
function get_columns_flat_at(array $columns, $level = 0) |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
$names = []; |
76
|
|
|
|
77
|
|
|
foreach ($columns as $column) { |
78
|
|
|
$parts = explode('.', $column); |
79
|
|
|
|
80
|
|
|
if (isset($parts[$level])) { |
81
|
|
|
$names[] = $parts[$level]; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return $names; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
if (!function_exists('get_csv_flat_columns')) { |
90
|
|
|
/** |
91
|
|
|
* Gets a CSV flat columns list from the given array |
92
|
|
|
* |
93
|
|
|
* @param array $columns |
94
|
|
|
* @param null $prefix |
95
|
|
|
* |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
function get_csv_flat_columns(array $columns, $prefix = null) |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
$flatColumns = []; |
101
|
|
|
$prefix = $prefix === null ? '' : $prefix . '.'; |
102
|
|
|
|
103
|
|
|
foreach ($columns as $key => $value) { |
104
|
|
|
if (is_array($value)) { |
105
|
|
|
$value = get_csv_flat_columns($value, $prefix . $key); |
106
|
|
|
} else { |
107
|
|
|
$value = $prefix . $key; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$flatColumns[] = $value; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
return implode(',', $flatColumns); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
if (!function_exists('get_array_flat_columns')) { |
118
|
|
|
/** |
119
|
|
|
* Gets an array flat columns list from the given array |
120
|
|
|
* |
121
|
|
|
* @param $columns |
122
|
|
|
* |
123
|
|
|
* @return array |
124
|
|
|
*/ |
125
|
|
|
function get_array_flat_columns($columns) |
|
|
|
|
126
|
|
|
{ |
127
|
|
|
// TODO: make sure array is passed??? |
128
|
|
|
return explode(',', get_csv_flat_columns($columns ?: [])); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
if (!function_exists('get_unflat_columns')) { |
132
|
|
|
/** |
133
|
|
|
* Gets the unflat version of flat (dot-notated) column list |
134
|
|
|
* |
135
|
|
|
* @param string|array $columns |
136
|
|
|
* |
137
|
|
|
* @return array |
138
|
|
|
*/ |
139
|
|
|
function get_unflat_columns($columns) |
|
|
|
|
140
|
|
|
{ |
141
|
|
|
$names = []; |
142
|
|
|
|
143
|
|
|
if (!is_array($columns)) { |
144
|
|
|
$columns = explode(',', $columns); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
foreach ($columns as $column) { |
148
|
|
|
$parts = explode('.', $column, 2); |
149
|
|
|
|
150
|
|
|
if (isset($parts[0])) { |
151
|
|
View Code Duplication |
if (!isset($names[$parts[0]])) { |
|
|
|
|
152
|
|
|
$names[$parts[0]] = null; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
if (isset($parts[1])) { |
156
|
|
View Code Duplication |
if ($names[$parts[0]] === null) { |
|
|
|
|
157
|
|
|
$names[$parts[0]] = []; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
$child = get_unflat_columns($parts[1]); |
161
|
|
|
$names[$parts[0]][key($child)] = current($child); |
162
|
|
|
}; |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
return $names; |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.