-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: Differentiate between kilobyte/kibibyte and megabyte/mebibyte #9277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
857da2a
refactor: differentiate between kilo/kibibytes and mega/mebibytes
ThomasMeschke 34b3cfd
add missing param declarations
ThomasMeschke 0f32963
add missing return type declarations
ThomasMeschke 8296dc3
add missing use statements
ThomasMeschke 5282aa3
replace pow with expression
ThomasMeschke 40a867f
add missing underline chars
ThomasMeschke 0e4f240
add missing blank line
ThomasMeschke 3ad691a
fix github actions
ThomasMeschke a9862ec
fix failing jobs
ThomasMeschke a186c0f
fix failing jobs
ThomasMeschke c7f21b1
fix failing jobs
ThomasMeschke bf9a9a8
Update user_guide_src/source/changelogs/v4.6.0.rst
ThomasMeschke 8829ea8
allow FileSizeUnit selection from String
ThomasMeschke 3767b29
revert refactoring of fallback call
ThomasMeschke f1464e3
substantiate deprecation message
ThomasMeschke 066c03d
refactor FileSizeUnit enum
ThomasMeschke 5bb2170
method names, visibility, return types
ThomasMeschke 9a3aacb
reorder enum fields, add user guide information
ThomasMeschke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of CodeIgniter 4 framework. | ||
* | ||
* (c) CodeIgniter Foundation <[email protected]> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CodeIgniter\Files; | ||
|
||
use CodeIgniter\Exceptions\InvalidArgumentException; | ||
|
||
enum FileSizeUnit: int | ||
{ | ||
case B = 0; | ||
case KB = 1; | ||
case MB = 2; | ||
case GB = 3; | ||
case TB = 4; | ||
|
||
/** | ||
* Allows the creation of a FileSizeUnit from Strings like "kb" or "mb" | ||
* | ||
* @throws InvalidArgumentException | ||
*/ | ||
public static function fromString(string $unit): self | ||
{ | ||
return match (strtolower($unit)) { | ||
'b' => self::B, | ||
'kb' => self::KB, | ||
'mb' => self::MB, | ||
'gb' => self::GB, | ||
'tb' => self::TB, | ||
default => throw new InvalidArgumentException("Invalid unit: {$unit}"), | ||
}; | ||
} | ||
} | ||
ThomasMeschke marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
use CodeIgniter\Files\FileSizeUnit; | ||
|
||
$bytes = $file->getSizeByBinaryUnit(); // 256901 | ||
$kibibytes = $file->getSizeByBinaryUnit(FileSizeUnit::KB); // 250.880 | ||
$mebibytes = $file->getSizeByBinaryUnit(FileSizeUnit::MB); // 0.245 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
use CodeIgniter\Files\FileSizeUnit; | ||
|
||
$bytes = $file->getSizeByMetricUnit(); // 256901 | ||
$kilobytes = $file->getSizeByMetricUnit(FileSizeUnit::KB); // 256.901 | ||
$megabytes = $file->getSizeByMetricUnit(FileSizeUnit::MB); // 0.256 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.