Skip to content

Commit

Permalink
reorder enum fields, add user guide information
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasMeschke committed Nov 26, 2024
1 parent 5bb2170 commit 9a3aacb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
14 changes: 7 additions & 7 deletions system/Files/FileSizeUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
*
Expand All @@ -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;
}
2 changes: 2 additions & 0 deletions user_guide_src/source/changelogs/v4.6.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ Model
Libraries
=========

- **File:** Added ``getSizeByBinaryUnit()`` and ``getSizeByMetricUnit()`` to ``File`` class.
See :ref:`File::getSizeByBinaryUnit() <file-get-size-by-binary-unit>` and :ref:`File::getSizeByMetricUnit() <file-get-size-by-metric-unit>`.
- **FileCollection:** Added ``retainMultiplePatterns()`` to ``FileCollection`` class.
See :ref:`FileCollection::retainMultiplePatterns() <file-collections-retain-multiple-patterns>`.
- **Validation:** Added ``min_dims`` validation rule to ``FileRules`` class. See
Expand Down
10 changes: 10 additions & 0 deletions user_guide_src/source/libraries/files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 9a3aacb

Please sign in to comment.