A PHP based framework agnostic library to convert several units
PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
docs/source
src
tests
.gitignore
.scrutinizer.yml
.travis.yml
LICENSE.md
README.md
composer.json
composer.lock
phpunit.xml.dist
unicorn.png

README.md

Unicorn

Code Coverage Build Status Scrutinizer Code Quality License Documentation Status

Unicorn Logo

A PHP based framework agnostic library to convert several units

Documentation

http://unicorn.readthedocs.io

Conversion example

Here is a quick example that shows how to convert 110 centimeters to meters:

$converter = new LengthConverter();

try {
    $result = $converter->convert(
        new ConvertibleValue('110', $converter::$centimeter),
        $converter::$meter
    );

    $result->getValue(); // '1.10...' with 999 decimals
    $result->getFloatValue(); // 1.1
    $result->getUnit()->getAbbreviation(); // 'm'
    $result->getUnit()->getName(); // 'meter'
} catch (UnsupportedUnitException $e) {
    // Unit might not be present in the converters units array
} catch (InvalidArgumentException $e) {
    // Something is wrong with the provided ConvertibleValue or Unit
}

Requirements

  • PHP 7.0 or higher
  • BCMath extension installed and enabled

Installation

Open a command console, enter your project directory and execute the following command to download the latest stable version of unicorn:

composer require xynnn/unicorn

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Authors

Philipp Bräutigam

Steffen Brand

License

Copyright (c) 2016 Philipp Bräutigam, Steffen Brand and contributors.
This repository is released under the GNU LGPL v3.0 license.