-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhpIniUtil.php
45 lines (39 loc) · 921 Bytes
/
PhpIniUtil.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Oro\Component\PhpUtils;
/**
* Converts a shorthand byte value to floating-point number.
*/
class PhpIniUtil
{
/**
* @param string $val
*
* @return float
*
* @see https://secure.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
*/
public static function parseBytes($val)
{
if (empty($val)) {
return 0;
}
preg_match('/([\-0-9]+)[\s]*([a-z]*)$/i', trim($val), $matches);
if (isset($matches[1])) {
$val = (int)$matches[1];
}
switch (strtolower($matches[2])) {
case 'g':
case 'gb':
$val *= 1024;
// no break
case 'm':
case 'mb':
$val *= 1024;
// no break
case 'k':
case 'kb':
$val *= 1024;
}
return (float)$val;
}
}