xynnn/unicorn

一个不依赖于框架的PHP库,用于转换多个单位

1.0.1 2017-01-25 17:11 UTC

This package is auto-updated.

Last update: 2024-09-16 21:51:02 UTC


README

Code Coverage Build Status Scrutinizer Code Quality License

Unicorn Logo

一个基于PHP的、不依赖于框架的库,用于转换多个单位

文档

http://unicorn.readthedocs.io

转换示例

以下是一个快速示例,展示如何将 110 厘米 转换为

$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
}

要求

  • PHP 7.0 或更高版本
  • 已安装并启用 BCMath 扩展

安装

打开命令行,进入您的项目目录,然后执行以下命令以下载Unicorn的最新稳定版本

composer require xynnn/unicorn

此命令需要您全局安装Composer,如Composer文档的安装章节中所述。

作者

Philipp Bräutigam

Steffen Brand

许可证

版权(c)2016 Philipp Bräutigam,Steffen Brand及贡献者。
此存储库在GNU LGPL v3.0许可证下发布。