ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ILIAS\Data\DataSize Class Reference

Class DataSize. More...

+ Collaboration diagram for ILIAS\Data\DataSize:

Public Member Functions

 __construct ($size, $unit)
 DataSize constructor. More...
 
 getSize ()
 The calculated data size. More...
 
 getUnit ()
 The unit which equals the class constant used to calculate the data size. More...
 
 __toString ()
 Returns the data size with the corresponding suffix. More...
 

Data Fields

const Byte = 1
 
const KiB = 1024
 
const MiB = 1048576
 
const GiB = 1073741824
 
const TiB = 1099511627776
 
const PiB = 1125899906842624
 
const EiB = 1152921504606846976
 
const ZiB = 1180591620717411303424
 
const YiB = 1208925819614629174706176
 
const KB = 1000
 
const MB = 1000000
 
const GB = 1000000000
 
const TB = 1000000000000
 
const PB = 1000000000000000
 
const EB = 1000000000000000000
 
const ZB = 1000000000000000000000
 
const YB = 1000000000000000000000000
 

Private Attributes

 $size
 
 $unit
 
 $suffix
 

Static Private Attributes

static $suffixMap
 

Detailed Description

Class DataSize.

This class provides the data size with additional information to remove the work to calculate the size to different unit like GiB, GB usw.

Author
Nicolas Schäfli ns@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Since
5.3
Version
1.0

Definition at line 15 of file DataSize.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Data\DataSize::__construct (   $size,
  $unit 
)

DataSize constructor.

Parameters
int$sizeThe data size in bytes.
int$unitThe unit which is used to calculate the data size.
Exceptions

Definition at line 91 of file DataSize.php.

References ILIAS\Data\DataSize\$size, ILIAS\Data\DataSize\$unit, and size.

92  {
93  if (!is_int($size)) {
94  throw new \InvalidArgumentException("Size must be of the type int.");
95  }
96 
97  if (!is_int($unit)) {
98  throw new \InvalidArgumentException("Unit must be of the type int.");
99  }
100 
101  if (!isset(self::$suffixMap[$unit])) {
102  throw new \InvalidArgumentException('The given data size unit is not valid, please check the provided class constants of the DataSize class.');
103  }
104 
105  $this->size = (float) $size / $unit; //the div operation can return int and float
106  $this->unit = $unit;
107  $this->suffix = self::$suffixMap[$unit];
108  }
font size
Definition: langcheck.php:162

Member Function Documentation

◆ __toString()

ILIAS\Data\DataSize::__toString ( )

Returns the data size with the corresponding suffix.

Example output: 1024 B 4096 GiB

Returns
string
Since
5.3

Definition at line 143 of file DataSize.php.

144  {
145  return "{$this->size} {$this->suffix}";
146  }

◆ getSize()

ILIAS\Data\DataSize::getSize ( )

◆ getUnit()

ILIAS\Data\DataSize::getUnit ( )

The unit which equals the class constant used to calculate the data size.

(self::GiB, ...)

Returns
int
Since
5.3

Definition at line 128 of file DataSize.php.

References ILIAS\Data\DataSize\$unit.

129  {
130  return $this->unit;
131  }

Field Documentation

◆ $size

float ILIAS\Data\DataSize::$size
private

Definition at line 71 of file DataSize.php.

Referenced by ILIAS\Data\DataSize\__construct(), and ILIAS\Data\DataSize\getSize().

◆ $suffix

string ILIAS\Data\DataSize::$suffix
private

Definition at line 79 of file DataSize.php.

◆ $suffixMap

ILIAS\Data\DataSize::$suffixMap
staticprivate
Initial value:
= [
self::Byte => 'B'

Definition at line 41 of file DataSize.php.

◆ $unit

int ILIAS\Data\DataSize::$unit
private

Definition at line 75 of file DataSize.php.

Referenced by ILIAS\Data\DataSize\__construct(), and ILIAS\Data\DataSize\getUnit().

◆ Byte

const ILIAS\Data\DataSize::Byte = 1

Definition at line 17 of file DataSize.php.

◆ EB

const ILIAS\Data\DataSize::EB = 1000000000000000000

Definition at line 35 of file DataSize.php.

◆ EiB

const ILIAS\Data\DataSize::EiB = 1152921504606846976

Definition at line 25 of file DataSize.php.

◆ GB

const ILIAS\Data\DataSize::GB = 1000000000

Definition at line 32 of file DataSize.php.

◆ GiB

const ILIAS\Data\DataSize::GiB = 1073741824

◆ KB

const ILIAS\Data\DataSize::KB = 1000

Definition at line 30 of file DataSize.php.

◆ KiB

const ILIAS\Data\DataSize::KiB = 1024

◆ MB

const ILIAS\Data\DataSize::MB = 1000000

Definition at line 31 of file DataSize.php.

◆ MiB

const ILIAS\Data\DataSize::MiB = 1048576

◆ PB

const ILIAS\Data\DataSize::PB = 1000000000000000

Definition at line 34 of file DataSize.php.

◆ PiB

const ILIAS\Data\DataSize::PiB = 1125899906842624

Definition at line 24 of file DataSize.php.

◆ TB

const ILIAS\Data\DataSize::TB = 1000000000000

Definition at line 33 of file DataSize.php.

◆ TiB

const ILIAS\Data\DataSize::TiB = 1099511627776

Definition at line 23 of file DataSize.php.

◆ YB

const ILIAS\Data\DataSize::YB = 1000000000000000000000000

Definition at line 37 of file DataSize.php.

◆ YiB

const ILIAS\Data\DataSize::YiB = 1208925819614629174706176

Definition at line 27 of file DataSize.php.

◆ ZB

const ILIAS\Data\DataSize::ZB = 1000000000000000000000

Definition at line 36 of file DataSize.php.

◆ ZiB

const ILIAS\Data\DataSize::ZiB = 1180591620717411303424

Definition at line 26 of file DataSize.php.


The documentation for this class was generated from the following file: