1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Zemit Framework. |
5
|
|
|
* |
6
|
|
|
* (c) Zemit Team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Zemit; |
13
|
|
|
|
14
|
|
|
use Phalcon\Debug\Dump; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class Utils |
18
|
|
|
*/ |
19
|
|
|
class Utils |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Remove time and memory limits |
23
|
|
|
*/ |
24
|
|
|
public static function setUnlimitedRuntime(): void |
25
|
|
|
{ |
26
|
|
|
ini_set('memory_limit', -1); |
27
|
|
|
ini_set('max_execution_time', 0); |
28
|
|
|
ini_set('max_input_time', 0); |
29
|
|
|
set_time_limit(0); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Set max upload file size and post size |
34
|
|
|
* @link https://www.php.net/manual/en/ini.list.php |
35
|
|
|
* @link https://www.php.net/manual/en/configuration.changes.modes.php |
36
|
|
|
* @deprecated This setting must be changed at the system level |
37
|
|
|
* @throws \Exception |
38
|
|
|
*/ |
39
|
|
|
public static function setMaxUploadFileSize(string $size = '2M'): void |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
throw new \Exception('This setting must be changed at the system level.'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get the Namespace from a class object |
46
|
|
|
*/ |
47
|
|
|
public static function getNamespace(object $class): string |
48
|
|
|
{ |
49
|
|
|
return (new \ReflectionClass($class))->getNamespaceName(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get the directory from a class object |
54
|
|
|
*/ |
55
|
|
|
public static function getDirname(object $class): string |
56
|
|
|
{ |
57
|
|
|
return dirname((new \ReflectionClass($class))->getFileName()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Return an array of the current memory usage in MB |
62
|
|
|
*/ |
63
|
|
|
public static function getMemoryUsage(): array |
64
|
|
|
{ |
65
|
|
|
$toMB = 1048576.2; |
66
|
|
|
return [ |
67
|
|
|
'memory' => (memory_get_usage() / $toMB) . ' MB', |
68
|
|
|
'memoryPeak' => (memory_get_peak_usage() / $toMB) . ' MB', |
69
|
|
|
'realMemory' => (memory_get_usage(true) / $toMB) . ' MB', |
70
|
|
|
'realMemoryPeak' => (memory_get_peak_usage(true) / $toMB) . ' MB', |
71
|
|
|
]; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
if (!function_exists('dd')) { |
76
|
|
|
/** |
77
|
|
|
* Dump the passed variables and end the script. |
78
|
|
|
*/ |
79
|
|
|
function dd(...$params): void |
80
|
|
|
{ |
81
|
|
|
dump(...$params); |
82
|
|
|
exit(1); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if (!function_exists('dump')) { |
87
|
|
|
/** |
88
|
|
|
* Dump the passed variables without ending the script. |
89
|
|
|
*/ |
90
|
|
|
function dump(...$params): void |
91
|
|
|
{ |
92
|
|
|
foreach ($params as $param) { |
93
|
|
|
$ret = (new Dump([], true))->variable($param); |
94
|
|
|
if (PHP_SAPI === 'cli') { |
95
|
|
|
$ret = strip_tags($ret) . PHP_EOL; |
96
|
|
|
} |
97
|
|
|
echo $ret; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.