|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the wow-apps/symfony-proxybonanza project |
|
4
|
|
|
* https://github.com/wow-apps/symfony-proxybonanza |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2016 WoW-Apps |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace WowApps\ProxybonanzaBundle\Traits; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Trait HelperTrait |
|
16
|
|
|
* @author Alexey Samara <[email protected]> |
|
17
|
|
|
* @package wow-apps/symfony-proxybonanza |
|
18
|
|
|
*/ |
|
19
|
|
|
trait HelperTrait |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @param string $date |
|
23
|
|
|
* @return \DateTime |
|
24
|
|
|
* @throws \InvalidArgumentException |
|
25
|
|
|
*/ |
|
26
|
|
|
public function convertDateTime(string $date): \DateTime |
|
27
|
|
|
{ |
|
28
|
|
|
return new \DateTime($date); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param int $bytes |
|
33
|
|
|
* @param int $precision |
|
34
|
|
|
* @return string |
|
35
|
|
|
*/ |
|
36
|
|
|
public function formatSizeUnits(int $bytes, int $precision = 2): string |
|
37
|
|
|
{ |
|
38
|
|
|
$units = ['B', 'Kb', 'Mb', 'Gb', 'Tb']; |
|
39
|
|
|
|
|
40
|
|
|
$bytes = max($bytes, 0); |
|
41
|
|
|
$pow = floor(($bytes ? log($bytes) : 0) / log(1024)); |
|
42
|
|
|
$pow = min($pow, count($units) - 1); |
|
43
|
|
|
|
|
44
|
|
|
$bytes /= pow(1024, $pow); |
|
45
|
|
|
|
|
46
|
|
|
return round($bytes, $precision) . $units[$pow]; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param \ArrayObject $arrayObject |
|
51
|
|
|
* @return array |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getArrayObjectKeys(\ArrayObject $arrayObject): array |
|
54
|
|
|
{ |
|
55
|
|
|
$keys = []; |
|
56
|
|
|
|
|
57
|
|
|
if (!empty($arrayObject)) { |
|
58
|
|
|
foreach ($arrayObject as $key => $value) { |
|
59
|
|
|
$keys[] = $key; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return $keys; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param float $timeStart |
|
68
|
|
|
* @return float |
|
69
|
|
|
*/ |
|
70
|
|
|
public function formatSpentTime(float $timeStart): float |
|
71
|
|
|
{ |
|
72
|
|
|
return round(microtime(true) - $timeStart, 2); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|