diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-01-23 10:55:31 +0100 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-02-07 11:23:29 +0100 |
commit | 94ecae4ade0b618c024708b747ee7da8b0fb7113 (patch) | |
tree | 7696ec87b3c201ede05403eb4878d4a680048954 /lib/private/MemoryInfo.php | |
parent | 0f8c34cdc65046d68339127849724ea6383aa4a8 (diff) | |
download | nextcloud-server-94ecae4ade0b618c024708b747ee7da8b0fb7113.tar.gz nextcloud-server-94ecae4ade0b618c024708b747ee7da8b0fb7113.zip |
Add helper to cast to int|float, fix MemoryInfo on 32bits
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib/private/MemoryInfo.php')
-rw-r--r-- | lib/private/MemoryInfo.php | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/private/MemoryInfo.php b/lib/private/MemoryInfo.php index ed6617d879d..266fb15a573 100644 --- a/lib/private/MemoryInfo.php +++ b/lib/private/MemoryInfo.php @@ -24,8 +24,11 @@ declare(strict_types=1); * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ + namespace OC; +use OCP\Util; + /** * Helper class that covers memory info. */ @@ -45,14 +48,14 @@ class MemoryInfo { /** * Returns the php memory limit. * - * @return int The memory limit in bytes. + * @return int|float The memory limit in bytes. */ - public function getMemoryLimit(): int { + public function getMemoryLimit(): int|float { $iniValue = trim(ini_get('memory_limit')); if ($iniValue === '-1') { return -1; - } elseif (is_numeric($iniValue) === true) { - return (int)$iniValue; + } elseif (is_numeric($iniValue)) { + return Util::numericToNumber($iniValue); } else { return $this->memoryLimitToBytes($iniValue); } @@ -62,11 +65,15 @@ class MemoryInfo { * Converts the ini memory limit to bytes. * * @param string $memoryLimit The "memory_limit" ini value - * @return int */ - private function memoryLimitToBytes(string $memoryLimit): int { + private function memoryLimitToBytes(string $memoryLimit): int|float { $last = strtolower(substr($memoryLimit, -1)); - $memoryLimit = (int)substr($memoryLimit, 0, -1); + $number = substr($memoryLimit, 0, -1); + if (is_numeric($number)) { + $memoryLimit = Util::numericToNumber($number); + } else { + throw new \InvalidArgumentException($number.' is not a valid numeric string (in memory_limit ini directive)'); + } // intended fall through switch ($last) { |