mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #8583 from wernerkrauss/fix-8572
Convert::memstring2bytes should return integer value
This commit is contained in:
commit
c3a52099e1
@ -556,7 +556,7 @@ class Convert
|
|||||||
* Preserves integer values like "1024" or "-1"
|
* Preserves integer values like "1024" or "-1"
|
||||||
*
|
*
|
||||||
* @param string $memString A memory limit string, such as "64M"
|
* @param string $memString A memory limit string, such as "64M"
|
||||||
* @return float
|
* @return int
|
||||||
*/
|
*/
|
||||||
public static function memstring2bytes($memString)
|
public static function memstring2bytes($memString)
|
||||||
{
|
{
|
||||||
@ -568,10 +568,10 @@ class Convert
|
|||||||
if ($unit) {
|
if ($unit) {
|
||||||
// Find the position of the unit in the ordered string which is the power
|
// Find the position of the unit in the ordered string which is the power
|
||||||
// of magnitude to multiply a kilobyte by
|
// of magnitude to multiply a kilobyte by
|
||||||
return round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
|
return (int)round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
|
||||||
}
|
}
|
||||||
|
|
||||||
return round($size);
|
return (int)round($size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace SilverStripe\Core\Tests;
|
namespace SilverStripe\Core\Tests;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use InvalidArgumentException;
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
use SilverStripe\Dev\SapphireTest;
|
use SilverStripe\Dev\SapphireTest;
|
||||||
use SilverStripe\View\Parsers\URLSegmentFilter;
|
use SilverStripe\View\Parsers\URLSegmentFilter;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
use Exception;
|
|
||||||
use InvalidArgumentException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test various functions on the {@link Convert} class.
|
* Test various functions on the {@link Convert} class.
|
||||||
@ -576,15 +576,15 @@ XML
|
|||||||
public function memString2BytesProvider()
|
public function memString2BytesProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
['-1', (float)-1],
|
'infinite' => ['-1', -1],
|
||||||
['2048', (float)(2 * 1024)],
|
'integer' => ['2048', 2 * 1024],
|
||||||
['2k', (float)(2 * 1024)],
|
'kilo' => ['2k', 2 * 1024],
|
||||||
['512M', (float)(512 * 1024 * 1024)],
|
'mega' => ['512M', 512 * 1024 * 1024],
|
||||||
['512MiB', (float)(512 * 1024 * 1024)],
|
'MiB' => ['512MiB', 512 * 1024 * 1024],
|
||||||
['512 mbytes', (float)(512 * 1024 * 1024)],
|
'mbytes' => ['512 mbytes', 512 * 1024 * 1024],
|
||||||
['512 megabytes', (float)(512 * 1024 * 1024)],
|
'megabytes' => ['512 megabytes', 512 * 1024 * 1024],
|
||||||
['1024g', (float)(1024 * 1024 * 1024 * 1024)],
|
'giga' => ['1024g', 1024 * 1024 * 1024 * 1024],
|
||||||
['1024G', (float)(1024 * 1024 * 1024 * 1024)]
|
'G' => ['1024G', 1024 * 1024 * 1024 * 1024]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,11 +607,11 @@ XML
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[200, '200B'],
|
[200, '200B'],
|
||||||
[(2 * 1024), '2K'],
|
[2 * 1024, '2K'],
|
||||||
[(512 * 1024 * 1024), '512M'],
|
[512 * 1024 * 1024, '512M'],
|
||||||
[(512 * 1024 * 1024 * 1024), '512G'],
|
[512 * 1024 * 1024 * 1024, '512G'],
|
||||||
[(512 * 1024 * 1024 * 1024 * 1024), '512T'],
|
[512 * 1024 * 1024 * 1024 * 1024, '512T'],
|
||||||
[(512 * 1024 * 1024 * 1024 * 1024 * 1024), '512P']
|
[512 * 1024 * 1024 * 1024 * 1024 * 1024, '512P']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user