-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSITransferRateUnit.php
More file actions
86 lines (77 loc) · 2.7 KB
/
SITransferRateUnit.php
File metadata and controls
86 lines (77 loc) · 2.7 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
declare(strict_types=1);
namespace Andante\Measurement\Unit\Digital\SI;
use Andante\Measurement\Contract\DimensionInterface;
use Andante\Measurement\Contract\UnitInterface;
use Andante\Measurement\Dimension\DataTransferRate;
use Andante\Measurement\Unit\SymbolNotation;
use Andante\Measurement\Unit\UnitSystem;
/**
* SI (decimal) Data Transfer Rate units.
*
* Includes both bit-based and byte-based transfer rates with decimal prefixes.
* 1 kbps = 1000 bps, 1 KB/s = 1000 B/s
*
* Supports multiple notations for bit-based units:
* - Default: "Gbps", "Mbps", etc. (most common)
* - IEEE: "Gbit/s", "Mbit/s", etc. (standards-compliant)
*/
enum SITransferRateUnit implements UnitInterface
{
// Bit-based
case BitPerSecond;
case KilobitPerSecond;
case MegabitPerSecond;
case GigabitPerSecond;
// Byte-based
case BytePerSecond;
case KilobytePerSecond;
case MegabytePerSecond;
case GigabytePerSecond;
public function symbol(SymbolNotation $notation = SymbolNotation::Default): string
{
return match ($this) {
self::BitPerSecond => match ($notation) {
SymbolNotation::IEEE, SymbolNotation::Unicode => 'bit/s',
default => 'bps',
},
self::KilobitPerSecond => match ($notation) {
SymbolNotation::IEEE, SymbolNotation::Unicode => 'kbit/s',
default => 'kbps',
},
self::MegabitPerSecond => match ($notation) {
SymbolNotation::IEEE, SymbolNotation::Unicode => 'Mbit/s',
default => 'Mbps',
},
self::GigabitPerSecond => match ($notation) {
SymbolNotation::IEEE, SymbolNotation::Unicode => 'Gbit/s',
default => 'Gbps',
},
self::BytePerSecond => 'B/s',
self::KilobytePerSecond => 'KB/s',
self::MegabytePerSecond => 'MB/s',
self::GigabytePerSecond => 'GB/s',
};
}
public function name(): string
{
return match ($this) {
self::BitPerSecond => 'bit per second',
self::KilobitPerSecond => 'kilobit per second',
self::MegabitPerSecond => 'megabit per second',
self::GigabitPerSecond => 'gigabit per second',
self::BytePerSecond => 'byte per second',
self::KilobytePerSecond => 'kilobyte per second',
self::MegabytePerSecond => 'megabyte per second',
self::GigabytePerSecond => 'gigabyte per second',
};
}
public function dimension(): DimensionInterface
{
return DataTransferRate::instance();
}
public function system(): UnitSystem
{
return UnitSystem::SI;
}
}