1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the unicorn project |
4
|
|
|
* |
5
|
|
|
* (c) Philipp Braeutigam <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Xynnn\Unicorn\Converter; |
12
|
|
|
|
13
|
|
|
use Xynnn\Unicorn\Model\Unit; |
14
|
|
|
use Xynnn\Unicorn\Model\ConvertibleValue; |
15
|
|
|
|
16
|
|
|
class DataTransferConverter extends AbstractMathematicalConverter |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var Unit $bit_per_second Static instance for conversions |
21
|
|
|
*/ |
22
|
|
|
public static $bit_per_second; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var Unit $kilobit_per_second Static instance for conversions |
26
|
|
|
*/ |
27
|
|
|
public static $kilobit_per_second; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Unit $megabit_per_second Static instance for conversions |
31
|
|
|
*/ |
32
|
|
|
public static $megabit_per_second; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var Unit $gigabit_per_second Static instance for conversions |
36
|
|
|
*/ |
37
|
|
|
public static $gigabit_per_second; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var Unit $terabit_per_second Static instance for conversions |
41
|
|
|
*/ |
42
|
|
|
public static $terabit_per_second; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var Unit $petabit_per_second Static instance for conversions |
46
|
|
|
*/ |
47
|
|
|
public static $petabit_per_second; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var Unit $exabit_per_second Static instance for conversions |
51
|
|
|
*/ |
52
|
|
|
public static $exabit_per_second; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var Unit $zettabit_per_second Static instance for conversions |
56
|
|
|
*/ |
57
|
|
|
public static $zettabit_per_second; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var Unit $yottabit_per_second Static instance for conversions |
61
|
|
|
*/ |
62
|
|
|
public static $yottabit_per_second; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var Unit $kibibit_per_second Static instance for conversions |
66
|
|
|
*/ |
67
|
|
|
public static $kibibit_per_second; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var Unit $mebibit_per_second Static instance for conversions |
71
|
|
|
*/ |
72
|
|
|
public static $mebibit_per_second; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var Unit $gibibit_per_second Static instance for conversions |
76
|
|
|
*/ |
77
|
|
|
public static $gibibit_per_second; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var Unit $tebibit_per_second Static instance for conversions |
81
|
|
|
*/ |
82
|
|
|
public static $tebibit_per_second; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var Unit $pebibit_per_second Static instance for conversions |
86
|
|
|
*/ |
87
|
|
|
public static $pebibit_per_second; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @var Unit $exibit_per_second Static instance for conversions |
91
|
|
|
*/ |
92
|
|
|
public static $exibit_per_second; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @var Unit $zebibit_per_second Static instance for conversions |
96
|
|
|
*/ |
97
|
|
|
public static $zebibit_per_second; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @var Unit $yobibit_per_second Static instance for conversions |
101
|
|
|
*/ |
102
|
|
|
public static $yobibit_per_second; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @var Unit $byte_per_second Static instance for conversions |
106
|
|
|
*/ |
107
|
|
|
public static $byte_per_second; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @var Unit $kilobyte_per_second Static instance for conversions |
111
|
|
|
*/ |
112
|
|
|
public static $kilobyte_per_second; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @var Unit $megabyte_per_second Static instance for conversions |
116
|
|
|
*/ |
117
|
|
|
public static $megabyte_per_second; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @var Unit $gigabyte_per_second Static instance for conversions |
121
|
|
|
*/ |
122
|
|
|
public static $gigabyte_per_second; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @var Unit $terabyte_per_second Static instance for conversions |
126
|
|
|
*/ |
127
|
|
|
public static $terabyte_per_second; |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @var Unit $petabyte_per_second Static instance for conversions |
131
|
|
|
*/ |
132
|
|
|
public static $petabyte_per_second; |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @var Unit $exabyte_per_second Static instance for conversions |
136
|
|
|
*/ |
137
|
|
|
public static $exabyte_per_second; |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @var Unit $zettabyte_per_second Static instance for conversions |
141
|
|
|
*/ |
142
|
|
|
public static $zettabyte_per_second; |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @var Unit $yottabyte_per_second Static instance for conversions |
146
|
|
|
*/ |
147
|
|
|
public static $yottabyte_per_second; |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @var Unit $kibibyte_per_second Static instance for conversions |
151
|
|
|
*/ |
152
|
|
|
public static $kibibyte_per_second; |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @var Unit $mebibyte_per_second Static instance for conversions |
156
|
|
|
*/ |
157
|
|
|
public static $mebibyte_per_second; |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @var Unit $gibibyte_per_second Static instance for conversions |
161
|
|
|
*/ |
162
|
|
|
public static $gibibyte_per_second; |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @var Unit $tebibyte_per_second Static instance for conversions |
166
|
|
|
*/ |
167
|
|
|
public static $tebibyte_per_second; |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @var Unit $pebibyte_per_second Static instance for conversions |
171
|
|
|
*/ |
172
|
|
|
public static $pebibyte_per_second; |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @var Unit $exibyte_per_second Static instance for conversions |
176
|
|
|
*/ |
177
|
|
|
public static $exibyte_per_second; |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @var Unit $zebibyte_per_second Static instance for conversions |
181
|
|
|
*/ |
182
|
|
|
public static $zebibyte_per_second; |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @var Unit $yobibyte_per_second Static instance for conversions |
186
|
|
|
*/ |
187
|
|
|
public static $yobibyte_per_second; |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* LengthConverter constructor. |
191
|
|
|
*/ |
192
|
5 |
|
public function __construct() |
193
|
|
|
{ |
194
|
5 |
|
$this->units[] = self::$bit_per_second = new Unit('Bit', 'Bit per second', '1000000'); |
195
|
5 |
|
$this->units[] = self::$kilobit_per_second = new Unit('Kilobit per second', 'Kbit/s', '1000'); |
196
|
5 |
|
$this->units[] = self::$megabit_per_second = new Unit('Megabit per second', 'Mbit/s', '1'); |
197
|
5 |
|
$this->units[] = self::$gigabit_per_second = new Unit('Gigabit per second', 'Gbit/s', '0.001'); |
198
|
5 |
|
$this->units[] = self::$terabit_per_second = new Unit('Terabit per second', 'Tbit/s', '0.000001'); |
199
|
5 |
|
$this->units[] = self::$petabit_per_second = new Unit('Petabit per second', 'Pbit/s', '0.000000001'); |
200
|
5 |
|
$this->units[] = self::$exabit_per_second = new Unit('Exabit per second', 'Ebit/s', '0.000000000001'); |
201
|
5 |
|
$this->units[] = self::$zettabit_per_second = new Unit('Zettabit per second', 'Zbit/s', '0.000000000000001'); |
202
|
5 |
|
$this->units[] = self::$yottabit_per_second = new Unit('Yottabit per second', 'Ybit/s', '0.000000000000000001'); |
203
|
|
|
|
204
|
5 |
|
$this->units[] = self::$kibibit_per_second = new Unit('Kibibit per second', 'Kibit/s', '976.5625'); |
205
|
5 |
|
$this->units[] = self::$mebibit_per_second = new Unit('Mebibit per second', 'Mibit/s', bcdiv(self::$kibibit_per_second->getFactor(), '1024', self::MAX_DECIMALS)); |
206
|
5 |
|
$this->units[] = self::$gibibit_per_second = new Unit('Gibibit per second', 'Gibit/s', bcdiv(self::$mebibit_per_second->getFactor(), '1024', self::MAX_DECIMALS)); |
207
|
5 |
|
$this->units[] = self::$tebibit_per_second = new Unit('Tebibit per second', 'Tibit/s', bcdiv(self::$gibibit_per_second->getFactor(), '1024', self::MAX_DECIMALS)); |
208
|
5 |
|
$this->units[] = self::$pebibit_per_second = new Unit('Pebibit per second', 'Pibit/s', bcdiv(self::$tebibit_per_second->getFactor(), '1024', self::MAX_DECIMALS)); |
209
|
5 |
|
$this->units[] = self::$exibit_per_second = new Unit('Exibit per second', 'Eibit/s', bcdiv(self::$pebibit_per_second->getFactor(), '1024', self::MAX_DECIMALS)); |
210
|
5 |
|
$this->units[] = self::$zebibit_per_second = new Unit('Zebibit per second', 'Zibit/s', bcdiv(self::$exibit_per_second->getFactor(), '1024', self::MAX_DECIMALS)); |
211
|
5 |
|
$this->units[] = self::$yobibit_per_second = new Unit('Yobibit per second', 'Yibit/s', bcdiv(self::$zebibit_per_second->getFactor(), '1024', self::MAX_DECIMALS)); |
212
|
|
|
|
213
|
5 |
|
$this->units[] = self::$byte_per_second = new Unit('Byte per second', 'B/s', '125000'); |
214
|
5 |
|
$this->units[] = self::$kilobyte_per_second = new Unit('Kilobyte per second', 'KB/s', '125'); |
215
|
5 |
|
$this->units[] = self::$megabyte_per_second = new Unit('Megabyte per second', 'MB/s', '0.125'); |
216
|
5 |
|
$this->units[] = self::$gigabyte_per_second = new Unit('Gigabyte per second', 'GB/s', '0.000125'); |
217
|
5 |
|
$this->units[] = self::$terabyte_per_second = new Unit('Terabyte per second', 'TB/s', '0.000000125'); |
218
|
5 |
|
$this->units[] = self::$petabyte_per_second = new Unit('Petabyte per second', 'PB/s', '0.000000000125'); |
219
|
5 |
|
$this->units[] = self::$exabyte_per_second = new Unit('Exabyte per second', 'EB/s', '0.000000000000125'); |
220
|
5 |
|
$this->units[] = self::$zettabyte_per_second = new Unit('Zettabyte per second', 'ZB/s', '0.000000000000000125'); |
221
|
5 |
|
$this->units[] = self::$yottabyte_per_second = new Unit('Yottabyte per second', 'YB/s', '0.000000000000000000125'); |
222
|
|
|
|
223
|
5 |
|
$this->units[] = self::$kibibyte_per_second = new Unit('Kibibyte per second', 'KiB/s', bcmul('0.11920929', '1024', self::MAX_DECIMALS)); |
224
|
5 |
|
$this->units[] = self::$mebibyte_per_second = new Unit('Mebibyte per second', 'MiB/s', '0.11920929'); |
225
|
5 |
|
$this->units[] = self::$gibibyte_per_second = new Unit('Gibibyte per second', 'GiB/s', bcdiv(self::$mebibyte_per_second->getFactor(), '1024', self::MAX_DECIMALS)); |
226
|
5 |
|
$this->units[] = self::$tebibyte_per_second = new Unit('Tebibyte per second', 'TiB/s', bcdiv(self::$gibibyte_per_second->getFactor(), '1024', self::MAX_DECIMALS)); |
227
|
5 |
|
$this->units[] = self::$pebibyte_per_second = new Unit('Pebibyte per second', 'PiB/s', bcdiv(self::$tebibyte_per_second->getFactor(), '1024', self::MAX_DECIMALS)); |
228
|
5 |
|
$this->units[] = self::$exibyte_per_second = new Unit('Exibyte per second', 'EiB/s', bcdiv(self::$pebibyte_per_second->getFactor(), '1024', self::MAX_DECIMALS)); |
229
|
5 |
|
$this->units[] = self::$zebibyte_per_second = new Unit('Zebibyte per second', 'ZiB/s', bcdiv(self::$exibyte_per_second->getFactor(), '1024', self::MAX_DECIMALS)); |
230
|
5 |
|
$this->units[] = self::$yobibyte_per_second = new Unit('Yobibyte per second', 'YiB/s', bcdiv(self::$zebibyte_per_second->getFactor(), '1024', self::MAX_DECIMALS)); |
231
|
5 |
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @return string Name of the converter |
235
|
|
|
*/ |
236
|
4 |
|
public function getName(): string |
237
|
|
|
{ |
238
|
4 |
|
return 'unicorn.converter.datatransfer'; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @param ConvertibleValue $cv The Convertible to be normalized |
243
|
|
|
*/ |
244
|
10 |
|
protected function normalize(ConvertibleValue $cv) |
245
|
|
|
{ |
246
|
10 |
|
parent::normalize($cv); |
247
|
10 |
|
$cv->setUnit(self::$megabit_per_second); |
248
|
10 |
|
} |
249
|
|
|
|
250
|
|
|
} |
251
|
|
|
|