generated from open-southeners/php-package-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
905 additions
and
159 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,28 +1,54 @@ | ||
title_goes_here [![required php version](https://img.shields.io/packagist/php-v/open-southeners/packagist_package_here)](https://www.php.net/supported-versions.php) [![codecov](https://codecov.io/gh/open-southeners/packagist_package_here/branch/main/graph/badge.svg?token=codecov_badge_token)](https://codecov.io/gh/open-southeners/packagist_package_here) [![Edit on VSCode online](https://img.shields.io/badge/vscode-edit%20online-blue?logo=visualstudiocode)](https://vscode.dev/github/open-southeners/packagist_package_here) | ||
Byte unit converter [![required php version](https://img.shields.io/packagist/php-v/open-southeners/byte-unit-converter)](https://www.php.net/supported-versions.php) [![codecov](https://codecov.io/gh/open-southeners/byte-unit-converter/branch/main/graph/badge.svg?token=qcEglkQDg4)](https://codecov.io/gh/open-southeners/byte-unit-converter) [![Edit on VSCode online](https://img.shields.io/badge/vscode-edit%20online-blue?logo=visualstudiocode)](https://vscode.dev/github/open-southeners/byte-unit-converter) | ||
=== | ||
|
||
and_description_here | ||
|
||
**Search & replace:** | ||
|
||
| Keys | Replacement | | ||
| --------------------------------------------------------- | ------------------------------------------------------------- | | ||
| `title_goes_here` | Fancy title from the repository (only README and stuff) | | ||
| `and_description_here` | Short package description (only for README and composer.json) | | ||
| `packagist_package_here` | Packagist (composer) published package name | | ||
| `codecov_badge_token` | Codecov token for the coverage badge | | ||
| `OpenSoutheners\PhpPackage`, `OpenSoutheners\\PhpPackage` | PSR-0 and PSR-4 complaint package namespace | | ||
A utility written in PHP8.1+ to convert multiple-byte units with no dependencies. | ||
|
||
## Getting started | ||
|
||
``` | ||
composer require open-southeners/packagist_package_here | ||
composer require open-southeners/byte-unit-converter | ||
``` | ||
|
||
### Usage | ||
|
||
**Before start using this package first familiarice with the concept of [multi-byte unit](https://en.wikipedia.org/wiki/Byte#Multiple-byte_units)**. | ||
|
||
Example usage: | ||
|
||
```php | ||
<?php | ||
|
||
use OpenSoutheners\ByteUnitConverter\BinaryByteUnit; | ||
use OpenSoutheners\ByteUnitConverter\DecimalByteUnit; | ||
use OpenSoutheners\ByteUnitConverter\ByteUnitConverter; | ||
|
||
// Using decimal system | ||
ByteUnitConverter::from(1, DecimalByteUnit::TB)->to(DecimalByteUnit::GB); // 1000 | ||
ByteUnitConverter::from(1, DecimalByteUnit::TB)->toGB(); // 1000 | ||
ByteUnitConverter::from(1, DecimalByteUnit::TB)->toGigabyte(); // 1000 | ||
ByteUnitConverter::conversion(1, DecimalByteUnit::TB, DecimalByteUnit::GB); // 1000 | ||
|
||
// Using binary system | ||
ByteUnitConverter::from(1, BinaryByteUnit::TiB)->to(BinaryByteUnit::GiB); // 1024 | ||
ByteUnitConverter::from(1, BinaryByteUnit::TiB)->toGiB(); // 1024 | ||
ByteUnitConverter::from(1, BinaryByteUnit::TiB)->toGibibyte(); // 1024 | ||
ByteUnitConverter::conversion(1, BinaryByteUnit::TiB, BinaryByteUnit::GiB); // 1024 | ||
``` | ||
|
||
### Considerations | ||
|
||
**We don't use round** or any method to remove extra decimals, **we consider this should be done by the developer using this library** so take this in mind. | ||
|
||
Also take in mind the different units within the enums, each one is using different conversion base (check usage). | ||
|
||
## Motivation | ||
|
||
After learning the Swift programming language I found a very useful utility under darwin systems (Mac OS X) which is the [ByteCountFormatter](https://developer.apple.com/documentation/foundation/bytecountformatter) there is where I based this project, also needed this for a long-run project (also used in our other package: [machine-stats](https://github.com/open-southeners/machine-stats)) therefore here it is. | ||
|
||
## Partners | ||
|
||
[![skore logo](https://github.com/open-southeners/partners/raw/main/logos/skore_logo.png)](https://getskore.com) | ||
|
||
## License | ||
|
||
This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). | ||
This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). |
This file was deleted.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
@@ -1,12 +1,9 @@ | ||
includes: | ||
- ./vendor/nunomaduro/larastan/extension.neon | ||
|
||
parameters: | ||
|
||
paths: | ||
- src | ||
|
||
# The level 8 is the highest level | ||
level: 5 | ||
level: 8 | ||
|
||
checkMissingIterableValueType: false |
This file contains 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,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="true" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupStaticProperties="false"> | ||
<coverage> | ||
<report> | ||
<clover outputFile="clover.xml"/> | ||
</report> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<ini name="memory_limit" value="2048M"/> | ||
</php> | ||
<source> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,22 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
colors="true" | ||
processIsolation="true" | ||
stopOnFailure="false" | ||
cacheDirectory=".phpunit.cache" | ||
backupStaticProperties="false" | ||
> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="true" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupStaticProperties="false"> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<ini name="memory_limit" value="2048M"/> | ||
<env name="DB_CONNECTION" value="sqlite" force="true"/> | ||
<env name="DB_DATABASE" value=":memory:" force="true"/> | ||
</php> | ||
</phpunit> |
This file contains 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,70 @@ | ||
<?php | ||
|
||
namespace OpenSoutheners\ByteUnitConverter; | ||
|
||
/** | ||
* This enum serves as a type safety for byte units based on the binary system. | ||
* | ||
* @see https://en.wikipedia.org/wiki/Binary_prefix | ||
* | ||
* @author Rubén Robles <me@d8vjork.com> | ||
*/ | ||
enum BinaryByteUnit: int implements ByteUnit | ||
{ | ||
use ComparesByteUnits; | ||
|
||
/** | ||
* Quebibyte | ||
*/ | ||
case QiB = 10; | ||
|
||
/** | ||
* Robibyte | ||
*/ | ||
case RiB = 9; | ||
|
||
/** | ||
* Yobibyte | ||
*/ | ||
case YiB = 8; | ||
|
||
/** | ||
* Zebibyte | ||
*/ | ||
case ZiB = 7; | ||
|
||
/** | ||
* Exbibyte | ||
*/ | ||
case EiB = 6; | ||
|
||
/** | ||
* Pebibyte | ||
*/ | ||
case PiB = 5; | ||
|
||
/** | ||
* Tebibyte | ||
*/ | ||
case TiB = 4; | ||
|
||
/** | ||
* Gibibyte | ||
*/ | ||
case GiB = 3; | ||
|
||
/** | ||
* Mebibyte | ||
*/ | ||
case MiB = 2; | ||
|
||
/** | ||
* Kibibyte | ||
*/ | ||
case KiB = 1; | ||
|
||
/** | ||
* Byte | ||
*/ | ||
case B = 0; | ||
} |
This file contains 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,15 @@ | ||
<?php | ||
|
||
namespace OpenSoutheners\ByteUnitConverter; | ||
|
||
/** | ||
* Mock interface used only for type safety on byte unit enums. | ||
* | ||
* @author Rubén Robles <me@d8vjork.com> | ||
* | ||
* @property-read int $value | ||
*/ | ||
interface ByteUnit extends \BackedEnum | ||
{ | ||
// | ||
} |
Oops, something went wrong.