1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the unicorn project |
4
|
|
|
* |
5
|
|
|
* (c) Philipp Braeutigam <[email protected]>, Steffen Brand <[email protected]> and contributors |
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
|
|
|
|
15
|
|
|
class DataStorageConverter extends AbstractMathematicalConverter |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var Unit $byte Static instance for conversions |
20
|
|
|
*/ |
21
|
|
|
public static $byte; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Unit $kilobyte Static instance for conversions |
25
|
|
|
*/ |
26
|
|
|
public static $kilobyte; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Unit $megabyte Static instance for conversions |
30
|
|
|
*/ |
31
|
|
|
public static $megabyte; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var Unit $gigabyte Static instance for conversions |
35
|
|
|
*/ |
36
|
|
|
public static $gigabyte; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var Unit $terabyte Static instance for conversions |
40
|
|
|
*/ |
41
|
|
|
public static $terabyte; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var Unit $petabyte Static instance for conversions |
45
|
|
|
*/ |
46
|
|
|
public static $petabyte; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var Unit $exabyte Static instance for conversions |
50
|
|
|
*/ |
51
|
|
|
public static $exabyte; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var Unit $zettabyte Static instance for conversions |
55
|
|
|
*/ |
56
|
|
|
public static $zettabyte; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var Unit $yottabyte Static instance for conversions |
60
|
|
|
*/ |
61
|
|
|
public static $yottabyte; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var Unit $kibibyte Static instance for conversions |
65
|
|
|
*/ |
66
|
|
|
public static $kibibyte; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var Unit $mebibyte Static instance for conversions |
70
|
|
|
*/ |
71
|
|
|
public static $mebibyte; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @var Unit $gibibyte Static instance for conversions |
75
|
|
|
*/ |
76
|
|
|
public static $gibibyte; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @var Unit $tebibyte Static instance for conversions |
80
|
|
|
*/ |
81
|
|
|
public static $tebibyte; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @var Unit $pebibyte Static instance for conversions |
85
|
|
|
*/ |
86
|
|
|
public static $pebibyte; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @var Unit $exibyte Static instance for conversions |
90
|
|
|
*/ |
91
|
|
|
public static $exibyte; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @var Unit $zebibyte Static instance for conversions |
95
|
|
|
*/ |
96
|
|
|
public static $zebibyte; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @var Unit $yobibyte Static instance for conversions |
100
|
|
|
*/ |
101
|
|
|
public static $yobibyte; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @var Unit $bit Static instance for conversions |
105
|
|
|
*/ |
106
|
|
|
public static $bit; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @var Unit $kilobit Static instance for conversions |
110
|
|
|
*/ |
111
|
|
|
public static $kilobit; |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @var Unit $megabit Static instance for conversions |
115
|
|
|
*/ |
116
|
|
|
public static $megabit; |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @var Unit $gigabit Static instance for conversions |
120
|
|
|
*/ |
121
|
|
|
public static $gigabit; |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @var Unit $terabit Static instance for conversions |
125
|
|
|
*/ |
126
|
|
|
public static $terabit; |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @var Unit $petabit Static instance for conversions |
130
|
|
|
*/ |
131
|
|
|
public static $petabit; |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @var Unit $exabit Static instance for conversions |
135
|
|
|
*/ |
136
|
|
|
public static $exabit; |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @var Unit $zettabit Static instance for conversions |
140
|
|
|
*/ |
141
|
|
|
public static $zettabit; |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @var Unit $yottabit Static instance for conversions |
145
|
|
|
*/ |
146
|
|
|
public static $yottabit; |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @var Unit $kibibit Static instance for conversions |
150
|
|
|
*/ |
151
|
|
|
public static $kibibit; |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @var Unit $mebibit Static instance for conversions |
155
|
|
|
*/ |
156
|
|
|
public static $mebibit; |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @var Unit $gibibit Static instance for conversions |
160
|
|
|
*/ |
161
|
|
|
public static $gibibit; |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @var Unit $tebibit Static instance for conversions |
165
|
|
|
*/ |
166
|
|
|
public static $tebibit; |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @var Unit $pebibit Static instance for conversions |
170
|
|
|
*/ |
171
|
|
|
public static $pebibit; |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @var Unit $exibit Static instance for conversions |
175
|
|
|
*/ |
176
|
|
|
public static $exibit; |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @var Unit $zebibit Static instance for conversions |
180
|
|
|
*/ |
181
|
|
|
public static $zebibit; |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @var Unit $yobibit Static instance for conversions |
185
|
|
|
*/ |
186
|
|
|
public static $yobibit; |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* LengthConverter constructor. |
190
|
|
|
*/ |
191
|
5 |
|
public function __construct() |
192
|
|
|
{ |
193
|
5 |
|
$this->units[] = self::$byte = new Unit('Byte', 'B', '1000000'); |
194
|
5 |
|
$this->units[] = self::$kilobyte = new Unit('Kilobyte', 'KB', '1000'); |
195
|
5 |
|
$this->units[] = self::$megabyte = new Unit('Megabyte', 'MB', '1'); |
196
|
5 |
|
$this->units[] = self::$gigabyte = new Unit('Gigabyte', 'GB', '0.001'); |
197
|
5 |
|
$this->units[] = self::$terabyte = new Unit('Terabyte', 'TB', '0.000001'); |
198
|
5 |
|
$this->units[] = self::$petabyte = new Unit('Petabyte', 'PB', '0.000000001'); |
199
|
5 |
|
$this->units[] = self::$exabyte = new Unit('Exabyte', 'EB', '0.000000000001'); |
200
|
5 |
|
$this->units[] = self::$zettabyte = new Unit('Zettabyte', 'ZB', '0.000000000000001'); |
201
|
5 |
|
$this->units[] = self::$yottabyte = new Unit('Yottabyte', 'YB', '0.000000000000000001'); |
202
|
|
|
|
203
|
5 |
|
$this->units[] = self::$kibibyte = new Unit('Kibibyte', 'KiB', '976.5625'); |
204
|
5 |
|
$this->units[] = self::$mebibyte = new Unit('Mebibyte', 'MiB', bcdiv(self::$kibibyte->getFactor(), '1024', self::MAX_DECIMALS)); |
205
|
5 |
|
$this->units[] = self::$gibibyte = new Unit('Gibibyte', 'GiB', bcdiv(self::$mebibyte->getFactor(), '1024', self::MAX_DECIMALS)); |
206
|
5 |
|
$this->units[] = self::$tebibyte = new Unit('Tebibyte', 'TiB', bcdiv(self::$gibibyte->getFactor(), '1024', self::MAX_DECIMALS)); |
207
|
5 |
|
$this->units[] = self::$pebibyte = new Unit('Pebibyte', 'PiB', bcdiv(self::$tebibyte->getFactor(), '1024', self::MAX_DECIMALS)); |
208
|
5 |
|
$this->units[] = self::$exibyte = new Unit('Exibyte', 'EiB', bcdiv(self::$pebibyte->getFactor(), '1024', self::MAX_DECIMALS)); |
209
|
5 |
|
$this->units[] = self::$zebibyte = new Unit('Zebibyte', 'ZiB', bcdiv(self::$exibyte->getFactor(), '1024', self::MAX_DECIMALS)); |
210
|
5 |
|
$this->units[] = self::$yobibyte = new Unit('Yobibyte', 'YiB', bcdiv(self::$zebibyte->getFactor(), '1024', self::MAX_DECIMALS)); |
211
|
|
|
|
212
|
5 |
|
$this->units[] = self::$bit = new Unit('Bit', 'bit', '8000000'); |
213
|
5 |
|
$this->units[] = self::$kilobit = new Unit('Kilobit', 'Kbit', '8000'); |
214
|
5 |
|
$this->units[] = self::$megabit = new Unit('Megabit', 'Mbit', '8'); |
215
|
5 |
|
$this->units[] = self::$gigabit = new Unit('Gigabit', 'Gbit', '0.008'); |
216
|
5 |
|
$this->units[] = self::$terabit = new Unit('Terabit', 'Tbit', '0.000008'); |
217
|
5 |
|
$this->units[] = self::$petabit = new Unit('Petabit', 'Pbit', '0.000000008'); |
218
|
5 |
|
$this->units[] = self::$exabit = new Unit('Exabit', 'Ebit', '0.000000000008'); |
219
|
5 |
|
$this->units[] = self::$zettabit = new Unit('Zettabit', 'Zbit', '0.000000000000008'); |
220
|
5 |
|
$this->units[] = self::$yottabit = new Unit('Yottabit', 'Ybit', '0.000000000000000008'); |
221
|
|
|
|
222
|
5 |
|
$this->units[] = self::$kibibit = new Unit('Kibibit', 'Kibit', '7812.5'); |
223
|
5 |
|
$this->units[] = self::$mebibit = new Unit('Mebibit', 'Mibit', bcdiv(self::$kibibit->getFactor(), '1024', self::MAX_DECIMALS)); |
224
|
5 |
|
$this->units[] = self::$gibibit = new Unit('Gibibit', 'Gibit', bcdiv(self::$mebibit->getFactor(), '1024', self::MAX_DECIMALS)); |
225
|
5 |
|
$this->units[] = self::$tebibit = new Unit('Tebibit', 'Tibit', bcdiv(self::$gibibit->getFactor(), '1024', self::MAX_DECIMALS)); |
226
|
5 |
|
$this->units[] = self::$pebibit = new Unit('Pebibit', 'Pibit', bcdiv(self::$tebibit->getFactor(), '1024', self::MAX_DECIMALS)); |
227
|
5 |
|
$this->units[] = self::$exibit = new Unit('Exibit', 'Eibit', bcdiv(self::$pebibit->getFactor(), '1024', self::MAX_DECIMALS)); |
228
|
5 |
|
$this->units[] = self::$zebibit = new Unit('Zebibit', 'Zibit', bcdiv(self::$exibit->getFactor(), '1024', self::MAX_DECIMALS)); |
229
|
5 |
|
$this->units[] = self::$yobibit = new Unit('Yobibit', 'Yibit', bcdiv(self::$zebibit->getFactor(), '1024', self::MAX_DECIMALS)); |
230
|
5 |
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @return string Name of the converter |
234
|
|
|
*/ |
235
|
4 |
|
public function getName(): string |
236
|
|
|
{ |
237
|
4 |
|
return 'unicorn.converter.datastorage'; |
238
|
|
|
} |
239
|
|
|
|
240
|
12 |
|
public function getBaseUnit(): Unit |
241
|
|
|
{ |
242
|
12 |
|
return self::$megabyte; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @param array $units |
247
|
|
|
*/ |
248
|
|
|
public function setUnits(array $units) |
249
|
|
|
{ |
250
|
|
|
$this->units = $units; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @param Unit $unit |
255
|
|
|
*/ |
256
|
|
|
public function addUnit(Unit $unit) |
257
|
|
|
{ |
258
|
|
|
$this->units[] = $unit; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
} |
262
|
|
|
|