|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class trait_config |
|
4
|
|
|
{ |
|
5
|
|
|
/** @param array Re-settable values for current table call */ |
|
6
|
|
|
protected static $config = [ |
|
7
|
|
|
'APP' => 'App', |
|
8
|
|
|
'DB_COLLATION_CI' => 'utf8mb4_general_ci', //UTF8_GENERAL_CI |
|
9
|
|
|
'EMPTY_TABLE_MSG' => 'No results found.', |
|
10
|
|
|
'EXPORT_FILE_NAME' => ':app - :items export (:datetime)', |
|
11
|
|
|
'FILTER_ACTIVE' => true, |
|
12
|
|
|
'FILTER_CASE_SENSITIVE' => false, |
|
13
|
|
|
'SAVES' => ['CSV', 'Excel'], |
|
14
|
|
|
'UTF8_ASC_SYMBOL' => '▲', |
|
15
|
|
|
'UTF8_DESC_SYMBOL' => '▼', |
|
16
|
|
|
'UTF8_LEFT_SYMBOL' => '‹', |
|
17
|
|
|
'UTF8_RIGHT_SYMBOL' => '›' |
|
18
|
|
|
]; |
|
19
|
|
|
|
|
20
|
|
|
/** Set/Get config value |
|
21
|
|
|
* @param mixed $value (string) Get if exists, (array) Set if valid |
|
22
|
|
|
* @return mixed */ |
|
23
|
|
|
public static function config($value) |
|
24
|
|
|
{ |
|
25
|
|
|
try { |
|
26
|
|
|
switch (gettype($value)) { |
|
27
|
|
|
case 'array': |
|
28
|
|
|
foreach ($value as $k => $v) { |
|
29
|
|
|
self::$config[$k] = self::valid((string) $k, $v); |
|
30
|
|
|
} |
|
31
|
|
|
break; |
|
32
|
|
|
case 'string': |
|
33
|
|
|
return self::valid($value); |
|
34
|
|
|
default: |
|
35
|
|
|
throw new Exception("Invalid value type."); |
|
36
|
|
|
} |
|
37
|
|
|
} catch (Exception $e) { |
|
38
|
|
|
self::error('ERROR: ' . $e->getMessage()); |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
private static function valid($key, $val = null) |
|
43
|
|
|
{ |
|
44
|
|
|
if (!array_key_exists($key, self::$config)) { |
|
45
|
|
|
throw new Exception('Request to undefined value: ' . $key); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
if ($val !== null) { |
|
49
|
|
|
if (empty($val) || gettype($val) !== gettype(self::$config[$key])) { |
|
50
|
|
|
throw new Exception("Setting invalid value: $val (:$key)"); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return $val === null ? self::$config[$key] : $val; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.