BASE . LOG,
'log_file_id' => $LOG_FILE_ID,
'log_per_date' => true,
]);
$byte_class = 'CoreLibs\Convert\Byte';
$PAGE_NAME = 'TEST CLASS: BYTE CONVERT';
print "";
print "
" . $PAGE_NAME . "";
print "";
print '';
print '' . $PAGE_NAME . '
';
// class
$byte = 254779258;
$string = '242.98 MB';
// static
print "S::BYTE TO (calls as var): $byte: " . $byte_class::humanReadableByteFormat($byte) . "
";
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte) . "
";
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_SI) . "
";
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST) . "
";
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_NOSPACE) . "
";
print "S::BYTE FROM: $string: " . Byte::stringByteFormat($string) . "
";
//
$byte = 314572800;
$string = '300 MB';
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte) . "
";
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_SI) . "
";
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST) . "
";
print "S::BYTE TO: $byte: "
. Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST | Byte::BYTE_FORMAT_NOSPACE) . "
";
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_NOSPACE) . "
";
print "S::BYTE FROM: $string: " . Byte::stringByteFormat($string) . "
";
// *** BYTES TEST ***
$bytes = [
-123123123,
999999, // KB-1
999999999, // MB-1
254779258, // MB-n
999999999999999, // TB-1
588795544887632, // TB-n
999999999999999999, // PB-1
9223372036854775807, // MAX INT
999999999999999999999, // EB-1
];
print "BYTE FORMAT TESTS
";
foreach ($bytes as $byte) {
print '';
//
print '
';
print "(" . number_format($byte) . "/" . $byte . ") bytes :";
$_bytes = Byte::humanReadableByteFormat($byte);
print '
';
print '
' . $_bytes . '
';
print '
';
try {
print Byte::stringByteFormat($_bytes);
} catch (\LengthException $e) {
print "LengthException 1: " . $e->getMessage();
try {
print "
S: " . Byte::stringByteFormat($_bytes, Byte::RETURN_AS_STRING);
} catch (\LengthException $e) {
print "LengthException 2: " . $e->getMessage();
} catch (\RuntimeException $e) {
print "RuntimeException 1: " . $e->getMessage();
}
}
print "
";
//
print "
";
//
print '';
//
print '
';
print "bytes [si]:";
$_bytes = Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_SI);
print '
' . $_bytes;
print '
';
try {
print Byte::stringByteFormat($_bytes);
} catch (\LengthException $e) {
print "LengthException A: " . $e->getMessage();
try {
print "
Ssi: " . Byte::stringByteFormat($_bytes, Byte::RETURN_AS_STRING | Byte::BYTE_FORMAT_SI);
} catch (\LengthException $e) {
print "LengthException B: " . $e->getMessage();
} catch (\RuntimeException $e) {
print "RuntimeException A: " . $e->getMessage();
}
}
print "
";
//
print "
";
}
$string_bytes = [
'-117.42 MB',
'242.98 MB',
'254.78 MiB',
'1 EiB',
'8 EB',
'867.36EB',
'1000EB',
'10000EB',
];
print "BYTE STRING TO BYTES TESTS
";
foreach ($string_bytes as $string) {
print '';
//
print '
';
print "string byte ($string) to bytes :";
try {
$_bytes = Byte::stringByteFormat($string);
} catch (\LengthException $e) {
print "
LengthException A: " . $e->getMessage();
$_bytes = 0;
}
try {
$_bytes_string = Byte::stringByteFormat($string, Byte::RETURN_AS_STRING);
} catch (\LengthException $e) {
print "
LengthException B: " . $e->getMessage();
$_bytes_string = '';
} catch (\RuntimeException $e) {
print "
RuntimeException: " . $e->getMessage();
$_bytes_string = '';
}
try {
$_bytes_si = Byte::stringByteFormat($string, Byte::BYTE_FORMAT_SI);
} catch (\LengthException $e) {
print "
LengthException A: " . $e->getMessage();
$_bytes_si = 0;
}
try {
$_bytes_string_si = Byte::stringByteFormat($string, Byte::RETURN_AS_STRING | Byte::BYTE_FORMAT_SI);
} catch (\LengthException $e) {
print "
LengthException B: " . $e->getMessage();
$_bytes_string_si = '';
} catch (\RuntimeException $e) {
print "
RuntimeException: " . $e->getMessage();
$_bytes_string_si = '';
}
print '
';
print '
'
. "F:" . number_format((int)$_bytes)
. '
B: ' . $_bytes
. '
S: ' . $_bytes_string
. "
Fsi:" . number_format((int)$_bytes_si)
. '
Bsi: ' . $_bytes_si
. '
Ssi: ' . $_bytes_string_si;
print '
';
print '
';
print "B: " . Byte::humanReadableByteFormat($_bytes) . "
";
print "Bsi: " . Byte::humanReadableByteFormat($_bytes_si, Byte::BYTE_FORMAT_SI);
print "
";
print "
";
}
print "";
// __END__