diff --git a/system/Files/FileSizeUnit.php b/system/Files/FileSizeUnit.php index 581582689f05..84c2ba44ca13 100644 --- a/system/Files/FileSizeUnit.php +++ b/system/Files/FileSizeUnit.php @@ -13,10 +13,16 @@ namespace CodeIgniter\Files; -use InvalidArgumentException; +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" * @@ -33,10 +39,4 @@ public static function fromString(string $unit): self default => throw new InvalidArgumentException("Invalid unit: {$unit}"), }; } - - case B = 0; - case KB = 1; - case MB = 2; - case GB = 3; - case TB = 4; } diff --git a/user_guide_src/source/changelogs/v4.6.0.rst b/user_guide_src/source/changelogs/v4.6.0.rst index 1dfee3dcd107..e68f60a0d4c4 100644 --- a/user_guide_src/source/changelogs/v4.6.0.rst +++ b/user_guide_src/source/changelogs/v4.6.0.rst @@ -215,6 +215,8 @@ Model Libraries ========= +- **File:** Added ``getSizeByBinaryUnit()`` and ``getSizeByMetricUnit()`` to ``File`` class. + See :ref:`File::getSizeByBinaryUnit() ` and :ref:`File::getSizeByMetricUnit() `. - **FileCollection:** Added ``retainMultiplePatterns()`` to ``FileCollection`` class. See :ref:`FileCollection::retainMultiplePatterns() `. - **Validation:** Added ``min_dims`` validation rule to ``FileRules`` class. See diff --git a/user_guide_src/source/libraries/files.rst b/user_guide_src/source/libraries/files.rst index 3c1dd6ae2376..df9f2f4b89dc 100644 --- a/user_guide_src/source/libraries/files.rst +++ b/user_guide_src/source/libraries/files.rst @@ -66,9 +66,14 @@ the results in kibibytes or mebibytes, respectively: A ``RuntimeException`` will be thrown if the file does not exist or an error occurs. + +.. _file-get-size-by-binary-unit: + getSizeByBinaryUnit() ===================== +.. versionadded:: 4.6.0 + Returns the size of the file default in bytes. You can pass in different FileSizeUnit values as the first parameter to get the results in kibibytes, mebibytes etc. respectively. You can pass in a precision value as the second parameter to define the amount of decimal places. @@ -78,9 +83,14 @@ the amount of decimal places. A ``RuntimeException`` will be thrown if the file does not exist or an error occurs. + +.. _file-get-size-by-metric-unit: + getSizeByMetricUnit() ===================== +.. versionadded:: 4.6.0 + Returns the size of the file default in bytes. You can pass in different FileSizeUnit values as the first parameter to get the results in kilobytes, megabytes etc. respectively. You can pass in a precision value as the second parameter to define the amount of decimal places.