定制 laxity7/phpmoney 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

laxity7/phpmoney

最新稳定版本:1.0.3

Composer 安装命令:

composer require laxity7/phpmoney

包简介

Correct work with money (fiat and crypto) in PHP

README 文档

README

PHP library to make working with money with fiat and cryptocurrencies safer and easier!

License Latest Stable Version Total Downloads

Install

Install via composer

composer require laxity7/phpmoney

Requirements

This library requires the BCMath PHP extension.

Version 1.0.0 requires PHP 8.1+. For older version of PHP, use version 0.0.1 of this library, which requires PHP 7.4.

Features

  • Fiat and cryptocurrency support
  • JSON Serialization
  • String representation
  • Transparent calculation logic upon availability
  • Money formatting
  • Currency repositories (ISO currencies and TOP100 cryptocurrencies included)

Usage

Basic usage example:

use Laxity7\Money\Money;
use Laxity7\Money\Currency;

$tenEur = new Money(10.50, 'EUR');
//$tenEur = new Money(10.50, new Currency('EUR')); // the same as above
$twentyOneEur = $tenEur->add($tenEur);
echo $twentyOneEur->getAmount(); // 21
echo $twentyOneEur->getCurrency(); // EUR
echo $twentyOneEur; // 21 EUR
echo json_encode($twentyOneEur); // {"amount":"21","currency":"EUR"}

$btc = new Money(0.00000001, 'BTC');
$eth = new Money(1.01, 'USDT');
$sum = $btc->add($eth); // throws \Laxity7\Money\Exceptions\InvalidArgumentException

Configuration example:

use Laxity7\Money\Money;
use Laxity7\Money\MoneyConfig;

// You can configure your own currencies only once. You can't change it later.
// Scale is the number of decimal places in the currency (e.g. 2 for USD, 8 for BTC). Max is 14.
MoneyConfig::configure(
    new Currencies([
        ['name' => 'US Dollar', 'symbol' => 'USD', 'scale' => 2],
        ['name' => 'Euro', 'symbol' => 'EUR', 'scale' => 4],
        ['name' => 'MyCoin', 'symbol' => 'MC', 'scale' => 8],
   ]
);


//...
$tenEur = new Money(10.50, 'USD'); // ok
$tenMyCoin = new Money(10.50, 'MyCoin'); // ok
$tenBtc = new Money(10.50, 'BTC'); // throws \Laxity7\Money\Exceptions\UnacceptableCurrencyException

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固