fixed bytes convertion method, again

This commit is contained in:
Jean-François Simon 2013-03-27 09:25:50 +01:00
parent bbb516f657
commit 233b945f64
5 changed files with 14 additions and 6 deletions

View File

@ -29,11 +29,11 @@ class ServerParams
return null;
}
if (preg_match('#^\+?(0X?)?([^KMG]*)([KMG]?)#', $iniMax, $match)) {
if (preg_match('#^\+?(0X?)?(.*?)([KMG]?)$#', $iniMax, $match)) {
$shifts = array('' => 0, 'K' => 10, 'M' => 20, 'G' => 30);
$bases = array('' => 10, '0' => 8, '0X' => 16);
return (intval($match[2], $bases[$match[1]]) * (1 << $shifts[$match[3]]));
return intval($match[2], $bases[$match[1]]) << $shifts[$match[3]];
}
return 0;

View File

@ -30,6 +30,7 @@ class ServerParamsTest extends \PHPUnit_Framework_TestCase
return array(
array('2k', 2048),
array('2 k', 2048),
array('8m', 8 * 1024 * 1024),
array('+2 k', 2048),
array('+2???k', 2048),
array('0x10', 16),
@ -37,6 +38,9 @@ class ServerParamsTest extends \PHPUnit_Framework_TestCase
array('010', 8),
array('+0x10 k', 16 * 1024),
array('1g', 1024 * 1024 * 1024),
array('-1', -1),
array('0', 0),
array('2mk', 2048), // the unit must be the last char, so in this case 'k', not 'm'
);
}
}

View File

@ -237,11 +237,11 @@ class UploadedFile extends File
return PHP_INT_MAX;
}
if (preg_match('#^\+?(0x?)?([^kmg]*)([kmg]?)#', $max, $match)) {
if (preg_match('#^\+?(0x?)?(.*?)([kmg]?)$#', $max, $match)) {
$shifts = array('' => 0, 'k' => 10, 'm' => 20, 'g' => 30);
$bases = array('' => 10, '0' => 8, '0x' => 16);
return (intval($match[2], $bases[$match[1]]) * (1 << $shifts[$match[3]]));
return intval($match[2], $bases[$match[1]]) << $shifts[$match[3]];
}
return 0;

View File

@ -79,11 +79,11 @@ class MemoryDataCollector extends DataCollector
return -1;
}
if (preg_match('#^\+?(0x?)?([^kmg]*)([kmg]?)#', $memoryLimit, $match)) {
if (preg_match('#^\+?(0x?)?(.*?)([kmg]?)$#', $memoryLimit, $match)) {
$shifts = array('' => 0, 'k' => 10, 'm' => 20, 'g' => 30);
$bases = array('' => 10, '0' => 8, '0x' => 16);
return (intval($match[2], $bases[$match[1]]) * (1 << $shifts[$match[3]]));
return intval($match[2], $bases[$match[1]]) << $shifts[$match[3]];
}
return 0;

View File

@ -48,6 +48,7 @@ class MemoryDataCollectorTest extends \PHPUnit_Framework_TestCase
return array(
array('2k', 2048),
array('2 k', 2048),
array('8m', 8 * 1024 * 1024),
array('+2 k', 2048),
array('+2???k', 2048),
array('0x10', 16),
@ -55,6 +56,9 @@ class MemoryDataCollectorTest extends \PHPUnit_Framework_TestCase
array('010', 8),
array('+0x10 k', 16 * 1024),
array('1g', 1024 * 1024 * 1024),
array('-1', -1),
array('0', 0),
array('2mk', 2048), // the unit must be the last char, so in this case 'k', not 'm'
);
}
}