承接 lase-peco/unit-converter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lase-peco/unit-converter

最新稳定版本:1.2

Composer 安装命令:

composer require lase-peco/unit-converter

包简介

A simple unit converter.

README 文档

README

Latest Version on Packagist Total Downloads

A simple unite converter library

Installation

Install the package via composer:

composer require lase-peco/unit-converter

Then publish the config file conversions.php with the following command

php artisan vendor:publish --provider="LasePeCo\UnitConverter\ServiceProvider"

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:

'area' => [
        'mm^2' => 1000000,
        'm^2' => 1, // base unit.
        'ft^2' => 10.7639,
        'yd^2' => 1.19598888894151,
        'km^2' => 0.000001, // your new unit and its value compared to the base unit.
    ],

Then create Area class in App\Units\ which should extends the base Area class of this package:

<?php
namespace App\Units;
use LasePeCo\UnitConverter\Units\Area as BaseArea;

class Area extends BaseArea
{
    public const SquareKiloMeter = 'km^2';
}

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.

use LasePeCo\UnitConverter\Facades\Converter;

Converter::getSupportedSystems(); 

// return

 [
  'metrics'  => 'Metrics',
  'uk'       => 'UK',
  'us_feet'  => 'US feet',
  'us_yards' => 'US yards'
 ]

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.

use LasePeCo\UnitConverter\Facades\Converter;
use App\Units\Area;

Converter::area(Area::SquareKiloMeter, Area::SquareMeter, 1); // return 1000000
Converter::area(Area::SquareMeter, Area::SquareYard, 10, 4); // return 11.9599

Density

The implemented density units are: KilogramPerCubicMeter, TonPerCubicMeter, PoundPerCubicFoot.

use LasePeCo\UnitConverter\Facades\Converter;
use App\Units\Density;

Converter::density(Density::KilogramPerCubicMeter, Density::PoundPerCubicFoot, 1, 6); // return 0.062428

Length

The implemented length units are: Millimeter, Meter, Inch.

use LasePeCo\UnitConverter\Facades\Converter;
use App\Units\Length;

Converter::length(Length::Meter, Length::Inch, 1, 4); // return 39.3701

Mass

The implemented mass units are: Kilogram, Ton, ImperialTon, USTon, Pound, Gram, Ounce.

use LasePeCo\UnitConverter\Facades\Converter;
use App\Units\Mass;

Converter::mass(Mass::Kilogram, Mass::Pound, 1); // return 2.2

Volume

The implemented volume units are: CubicDecimeter, CubicMeter, CubicFoot, CubicYard.

use LasePeCo\UnitConverter\Facades\Converter;
use App\Units\Volume;

Converter::volume(Volume::CubicMeter, Volume::CubicFoot, 1); // return 35.31

Speed

The implemented speed units are: MillimeterPerSecond, MeterPerSecond, FootPerSecond, YardPerSecond.

use LasePeCo\UnitConverter\Facades\Converter;
use App\Units\Speed;

Converter::speed(Speed::MeterPerSecond, Speed::FootPerSecond, 1); // return 3.28

Volumetric flow rate

The implemented volumetric flow rate units are: CubicDecimeterPerHour, CubicMeterPerHour, CubicFootPerHour, CubicYardPerHour.

use LasePeCo\UnitConverter\Facades\Converter;
use App\Units\VolumetricFlowRate;

Converter::volumetric_flow_rate(VolumetricFlowRate::CubicMeterPerHour, VolumetricFlowRate::CubicDecimeterPerHour, 1)); // return 1000

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email a.dabak@lase-peco.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

lase-peco/unit-converter 适用场景与选型建议

lase-peco/unit-converter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 89 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 09 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 lase-peco/unit-converter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 lase-peco/unit-converter 我们能提供哪些服务?
定制开发 / 二次开发

基于 lase-peco/unit-converter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 89
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-09-21