Download the PHP package apiotrowski/unit-converter without Composer
On this page you can find all versions of the php package apiotrowski/unit-converter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download apiotrowski/unit-converter
More information about apiotrowski/unit-converter
Files in apiotrowski/unit-converter
Package unit-converter
Short Description Unit converter it is service which converts values based on raw string query.
License proprietary
Informations about the package unit-converter
Unit Converter
Unit converter it is php service which converts values based on raw string query.
QueryExample: 10cm to ?in
Converter will automatically resolve supported converter and make calculation. In the output it return new Value.
Value is an Object what have two property: Value (string), Unit (object).
Manual conversion
If you want to convert values not using Convert Manager you can do it directly by calling following snippet:
Current converters list implemented inside:
- Length Converter (unit: ml, km, m, cm, in, ft)
- Weight Converter (unit: t, kg, g, dag, lbs, oz)
How to use it
Unit Converter is really simple to use and easy to extend. In a bellow example I show how to use this tool.
After you call convert() function all magic happened inside. At the beginning it resolve the query to php form, choose what converter should be used, and in the end converts value to destination unit.
In the output ($convertedValue) you get Value object with the result.
To calculation values tool is use BC Math library.
Tool are tested in PHPUnit, so everything should work Without any mistake.
How to extend Unit Converter
To Extend Converter User should:
-
Create new Converter class and Unit class,
-
Add new created Unit class to list of the supported units in the UnitFactory class,
- During initialization of ConvertManager, add your converter class to list of supported converters.
Supported PHP Versions
- PHP 7.0 with installed BC Math Extension
All versions of unit-converter with dependencies
ext-bcmath Version *