Skip to content

Commit 8829ea8

Browse files
allow FileSizeUnit selection from String
Co-authored-by: Michal Sniatala <[email protected]>
1 parent bf9a9a8 commit 8829ea8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

system/Files/FileSizeUnit.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,16 @@ enum FileSizeUnit: int
2020
case MB = 2;
2121
case GB = 3;
2222
case TB = 4;
23+
24+
public static function fromString(string $unit): self
25+
{
26+
return match (strtolower($unit)) {
27+
'b' => self::B,
28+
'kb' => self::KB,
29+
'mb' => self::MB,
30+
'gb' => self::GB,
31+
'tb' => self::TB,
32+
default => throw new InvalidArgumentException("Invalid unit: $unit"),
33+
};
34+
}
2335
}

0 commit comments

Comments
 (0)