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
|
|
|
class Utils |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Remove time and memory limits |
18
|
|
|
*/ |
19
|
1 |
|
public static function setUnlimitedRuntime(): void |
20
|
|
|
{ |
21
|
1 |
|
ini_set('memory_limit', -1); |
22
|
1 |
|
ini_set('max_execution_time', 0); |
23
|
1 |
|
ini_set('max_input_time', 0); |
24
|
1 |
|
set_time_limit(0); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Get the Namespace from a class object |
29
|
|
|
*/ |
30
|
1 |
|
public static function getNamespace(object $class): string |
31
|
|
|
{ |
32
|
1 |
|
return (new \ReflectionClass($class))->getNamespaceName(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get the Namespace from a class object |
37
|
|
|
*/ |
38
|
1 |
|
public static function getShortName(object $class): string |
39
|
|
|
{ |
40
|
1 |
|
return (new \ReflectionClass($class))->getShortName(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Get the Namespace from a class object |
45
|
|
|
*/ |
46
|
1 |
|
public static function getName(object $class): string |
47
|
|
|
{ |
48
|
1 |
|
return (new \ReflectionClass($class))->getName(); |
49
|
1 |
|
} |
50
|
1 |
|
|
51
|
1 |
|
/** |
52
|
1 |
|
* Get the directory from a class object |
53
|
1 |
|
*/ |
54
|
|
|
public static function getDirname(object $class): string |
55
|
|
|
{ |
56
|
|
|
return dirname((new \ReflectionClass($class))->getFileName()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Return an array of the current memory usage in MB |
61
|
|
|
*/ |
62
|
|
|
public static function getMemoryUsage(float $divider = 1048576.2, string $suffix = ' MB'): array |
63
|
|
|
{ |
64
|
|
|
return [ |
65
|
|
|
'memory' => (memory_get_usage() / $divider) . $suffix, |
66
|
|
|
'memoryPeak' => (memory_get_peak_usage() / $divider) . $suffix, |
67
|
|
|
'realMemory' => (memory_get_usage(true) / $divider) . $suffix, |
68
|
|
|
'realMemoryPeak' => (memory_get_peak_usage(true) / $divider) . $suffix, |
69
|
|
|
]; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|