Download the PHP package lase-peco/unit-converter without Composer
On this page you can find all versions of the php package lase-peco/unit-converter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package unit-converter
Unit converter
A simple unite converter library
Installation
Install the package via composer:
Then publish the config file conversions.php
with the following command
The config file conversions.php
contains all units of measurement and its values.
Define your own units
First add your unit in the config file und the matching section, then it is recommended to create a class That extends the base package class.
Example:
Say you want to add KM^2
as an Area
unit, first add the unit in the config file:
Then create Area
class in App\Units\
which should extends the base Area
class of this package:
We recommend using these classes to avoid typos in your code.
Usage
This package supports 4 measuring systems Metrics
, UK
, US feet
and US yards
.
To get all supported measuring systems you can call the function getSupportedSystems()
on the Converter
facade.
This package is also able to convert area
, density
, length
, mass
, volume
, volumetric flow rate
and speed
, these are functions you can call on the Converter
facade. Each of them have its own class where the units are defined as constants, to provide some strong typing.
All of these functions accept the same parameters:
string $from_unit
the unit, from which you are converting.
string $to_unit
the unit, to which you are converting.
float $measurement
the value.
int $decimals
(optional) the decimal accuracy. default is 2.
Area
The implemented area units are: SquareMillimeter, SquareMeter, SquareFoot, SquareYard
.
Density
The implemented density units are: KilogramPerCubicMeter, TonPerCubicMeter, PoundPerCubicFoot
.
Length
The implemented length units are: Millimeter, Meter, Inch
.
Mass
The implemented mass units are: Kilogram, Ton, ImperialTon, USTon, Pound, Gram, Ounce
.
Volume
The implemented volume units are: CubicDecimeter, CubicMeter, CubicFoot, CubicYard
.
Speed
The implemented speed units are: MillimeterPerSecond, MeterPerSecond, FootPerSecond, YardPerSecond
.
Volumetric flow rate
The implemented volumetric flow rate units are: CubicDecimeterPerHour, CubicMeterPerHour, CubicFootPerHour, CubicYardPerHour
.
Testing
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Ahmed Dabak
- Abdulsalam Emesh
- All Contributors
License
The MIT License (MIT). Please see License File for more information.