|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppUtils; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Parses the specified number, and returns a NumberInfo instance. |
|
7
|
|
|
* |
|
8
|
|
|
* @param mixed $value |
|
9
|
|
|
* @return \AppUtils\NumberInfo |
|
10
|
|
|
*/ |
|
11
|
|
|
function parseNumber($value, $forceNew=false) |
|
12
|
|
|
{ |
|
13
|
|
|
if($value instanceof NumberInfo && $forceNew !== true) { |
|
14
|
|
|
return $value; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
return new NumberInfo($value); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Parses the specified variable, and allows accessing |
|
22
|
|
|
* information on it. |
|
23
|
|
|
* |
|
24
|
|
|
* @param mixed $variable |
|
25
|
|
|
* @return \AppUtils\VariableInfo |
|
26
|
|
|
*/ |
|
27
|
|
|
function parseVariable($variable) |
|
28
|
|
|
{ |
|
29
|
|
|
return new VariableInfo($variable); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Like the native PHP function <code>parse_url</code>, |
|
34
|
|
|
* but with a friendly API and some enhancements and fixes |
|
35
|
|
|
* for a few things that the native function handles poorly. |
|
36
|
|
|
* |
|
37
|
|
|
* @param string $url The URL to parse. |
|
38
|
|
|
* @return \AppUtils\URLInfo |
|
39
|
|
|
*/ |
|
40
|
|
|
function parseURL(string $url) : URLInfo |
|
41
|
|
|
{ |
|
42
|
|
|
return new URLInfo($url); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Creates a throwable info instance for the specified error, |
|
47
|
|
|
* which enables accessing additional information on it, |
|
48
|
|
|
* as well as serializing it to be able to persist it in storage. |
|
49
|
|
|
* |
|
50
|
|
|
* @param \Throwable $e |
|
51
|
|
|
* @return ConvertHelper_ThrowableInfo |
|
52
|
|
|
*/ |
|
53
|
|
|
function parseThrowable(\Throwable $e) : ConvertHelper_ThrowableInfo |
|
54
|
|
|
{ |
|
55
|
|
|
return ConvertHelper_ThrowableInfo::fromThrowable($e); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Restores a throwable info instance from a previously |
|
60
|
|
|
* serialized array. |
|
61
|
|
|
* |
|
62
|
|
|
* @param array $serialized |
|
63
|
|
|
* @return ConvertHelper_ThrowableInfo |
|
64
|
|
|
*/ |
|
65
|
|
|
function restoreThrowable(array $serialized) : ConvertHelper_ThrowableInfo |
|
66
|
|
|
{ |
|
67
|
|
|
return ConvertHelper_ThrowableInfo::fromSerialized($serialized); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Creates an interval wrapper, that makes it a lot easier |
|
72
|
|
|
* to work with date intervals. It also solves |
|
73
|
|
|
* |
|
74
|
|
|
* @param \DateInterval $interval |
|
75
|
|
|
* @return ConvertHelper_DateInterval |
|
76
|
|
|
*/ |
|
77
|
|
|
function parseInterval(\DateInterval $interval) : ConvertHelper_DateInterval |
|
78
|
|
|
{ |
|
79
|
|
|
return ConvertHelper_DateInterval::fromInterval($interval); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Translation function used to translate some of the internal |
|
84
|
|
|
* strings: if the localization is installed, it will use this |
|
85
|
|
|
* to do the translation. |
|
86
|
|
|
* |
|
87
|
|
|
* @return string |
|
88
|
|
|
*/ |
|
89
|
|
|
function t() |
|
90
|
|
|
{ |
|
91
|
|
|
$args = func_get_args(); |
|
92
|
|
|
|
|
93
|
|
|
// is the localization package installed? |
|
94
|
|
|
if(class_exists('\AppLocalize\Localization')) |
|
95
|
|
|
{ |
|
96
|
|
|
return call_user_func_array('\AppLocalize\t', $args); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
// simulate the translation function |
|
100
|
|
|
return call_user_func_array('sprintf', $args); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Initializes the utilities: this is called automatically |
|
105
|
|
|
* because this file is included in the files list in the |
|
106
|
|
|
* composer.json, guaranteeing it is always loaded. |
|
107
|
|
|
*/ |
|
108
|
|
|
function init() |
|
109
|
|
|
{ |
|
110
|
|
|
if(!class_exists('\AppLocalize\Localization')) { |
|
111
|
|
|
return; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
$installFolder = realpath(__DIR__.'/../'); |
|
115
|
|
|
|
|
116
|
|
|
// Register the classes as a localization source, |
|
117
|
|
|
// so they can be found, and use the bundled localization |
|
118
|
|
|
// files. |
|
119
|
|
|
\AppLocalize\Localization::addSourceFolder( |
|
|
|
|
|
|
120
|
|
|
'application-utils', |
|
121
|
|
|
'Application Utils Package', |
|
122
|
|
|
'Composer Packages', |
|
123
|
|
|
$installFolder.'/localization', |
|
124
|
|
|
$installFolder.'/src' |
|
125
|
|
|
); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
init(); |
|
129
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths