承接 lusitanian/phpmoney 相关项目开发

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

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

lusitanian/phpmoney

Composer 安装命令:

composer require lusitanian/phpmoney

包简介

PHP Money Pattern Implementation

README 文档

README

PHPMoney is a unit-tested Money pattern implementation (sans currency -- which is on the TODO list) for PHP 5.3+

Installation (composer)

Add the following item to your composer.json's require section: "lusitanian/phpmoney": "dev-master"

Usage

The classes are set up in a PSR-0 compliant manner and will work with any PSR-0 autoloader if you don't install the package with composer (which generates an autoloader automatically). The library includes a MoneyFactory that will create Money instances for you using the best-available MathProvider that will work on your installation of PHP.

Example Usage

<?php
$factory = new PHPMoney\MoneyFactory();
$twoDollars = $factory->createMoney(200);
$threeDollars = $factory->createMoney(300);
$fiveDollars = $twoDollars->add($threeDollars);
echo $fiveDollars->format();

You can, of course, also create Money instances without the factory. You will need to pass each Money instance an instance of a MathProvider (you can and should use the same MathProvider instance for multiple Money objects).

<?php
$bcMathProvider = new PHPMoney\MathProvider\BCMathProvider();
$oneDollar = new PHPMoney\Money(100, $bcMathProvider);
$twoDollars = new PHPMoney\Money(200, $bcMathProvider);

Tests

The tests are in the tests folder and reach 100% code-coverage. You need phpunit to run them. A phpunit.xml file is included.

统计信息

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

GitHub 信息

  • Stars: 12
  • Watchers: 3
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-01-22