19 declare(strict_types=1);
36 public const KiB = 1024;
37 public const MiB = 1_048_576;
39 public const GiB = 1_073_741_824;
40 public const TiB = 1_099_511_627_776;
42 public const KB = 1000;
44 public const MB = 1_000_000;
46 public const GB = 1_000_000_000;
48 public const TB = 1_000_000_000_000;
88 $this->size = (float) $size / (
float)
$unit;
113 throw new \InvalidArgumentException(
'The given data size unit is not valid, please check the provided class constants of the DataSize class.');
149 case $size > self::SIZE_FACTOR * self::SIZE_FACTOR * self::SIZE_FACTOR * self::SIZE_FACTOR:
152 case $size > self::SIZE_FACTOR * self::SIZE_FACTOR * self::SIZE_FACTOR:
155 case $size > self::SIZE_FACTOR * self::SIZE_FACTOR:
158 case $size > self::SIZE_FACTOR:
166 $size = round($size / (
float) $unit, self::PRECISION);
mapUnitToSuffix(int $unit)
This class provides the data size with additional information to remove the work to calculate the siz...
inBytes()
Get the size in bytes.
static array $abbreviations
__toString()
Returns the data size in a human readable manner.
getSize()
The calculated data size.
getUnit()
The unit which equals the class constant used to calculate the data size.
__construct(int $size, int $unit)
DataSize constructor.