Fix #19526: Add the convertIniSizeToBytes method to BaseStringHelper

This commit is contained in:
Maksim Spirkov
2025-09-30 02:27:40 +04:00
committed by GitHub
parent 54fb1cc7af
commit d8ba4c0468
5 changed files with 55 additions and 44 deletions

View File

@ -52,6 +52,30 @@ class BaseStringHelper
return mb_substr((string)$string, $start, $length, '8bit');
}
/**
* Converts php.ini style size to bytes.
*
* @param string $string php.ini style size. Examples: `512M`, `1024K`, `1G`, `256`.
* @return int the number of bytes equivalent to the specified string.
* @since 2.0.54
*/
public static function convertIniSizeToBytes($string)
{
switch (substr($string, -1)) {
case 'M':
case 'm':
return (int) $string * 1048576;
case 'K':
case 'k':
return (int) $string * 1024;
case 'G':
case 'g':
return (int) $string * 1073741824;
default:
return (int) $string;
}
}
/**
* Returns the trailing name component of a path.
* This method is similar to the php function `basename()` except that it will