2017 © Pedro Peláez
 

library phpmoney

PHP Money Pattern Implementation

image

lusitanian/phpmoney

PHP Money Pattern Implementation

  • Sunday, January 27, 2013
  • by Lusitanian
  • Repository
  • 4 Watchers
  • 12 Stars
  • 4,756 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

PHPMoney

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

Installation (composer)

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

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., (*3)

Example Usage, (*4)

<?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)., (*5)

<?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., (*6)

The Versions

27/01 2013

dev-master

9999999-dev

PHP Money Pattern Implementation

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by David Desberg

pattern math money finance