forked from smalot/pdfparser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryLimit.php
More file actions
45 lines (38 loc) · 967 Bytes
/
Copy pathMemoryLimit.php
File metadata and controls
45 lines (38 loc) · 967 Bytes
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
/**
* @file This file is part of the PdfParser library.
*
* @author Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
*
* @date 2026-04-24
*
* @license LGPLv3
*
* @url <https://github.com/smalot/pdfparser>
*/
namespace Smalot\PdfParser\RawData;
final class MemoryLimit
{
/**
* Converts PHP ini memory values (for example "128M", "1G", "-1") to bytes.
*/
public static function toBytes(string $value): int
{
$value = trim($value);
if ('' === $value || '-1' === $value) {
return -1;
}
$unit = strtolower(substr($value, -1));
$number = (int) $value;
switch ($unit) {
case 'g':
return $number * 1024 * 1024 * 1024;
case 'm':
return $number * 1024 * 1024;
case 'k':
return $number * 1024;
default:
return (int) $value;
}
}
}