2017 © Pedro Peláez
 

library money

Fork of Mathias Verraes PHP implementation of Fowler's Money pattern

image

hemeragestao/money

Fork of Mathias Verraes PHP implementation of Fowler's Money pattern

  • Thursday, February 6, 2014
  • by gustavorssantos
  • Repository
  • 1 Watchers
  • 0 Stars
  • 162 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 232 Forks
  • 0 Open issues
  • 4 Versions
  • 3 % Grown

The README.md

Money

Fork from Mathias Verraes implementation of Fowley's money pattern., (*1)

The current version of the fork divverges from Fowley's pattern by using floats as parameters on the Money constructor. This was introduced in order to cater to the issue of large monetary entities overflowing PHP int size on 32 bits platforms. This will be dealt with on later releases of this fork, so expect API breakage on minor releases., (*2)

PHP 5.3+ library to make working with money safer, easier, and fun!, (*3)

"If I had a dime for every time I've seen someone use FLOAT to store currency, I'd have $999.997634" -- Bill Karwin, (*4)

In short: You shouldn't represent monetary values by a float. Wherever you need to represent money, use this Money value object., (*5)

<?php

use Money\Money;

$fiveEur = Money::EUR(5);
$tenEur = $fiveEur->add($fiveEur);

list($part1, $part2, $part3) = $tenEur->allocate(array(1, 1, 1));
assert($part1->equals(Money::EUR(334)));
assert($part2->equals(Money::EUR(333)));
assert($part3->equals(Money::EUR(333)));

The documentation is available at http://money.readthedocs.org, (*6)

Installation

Install the library using composer. Add the following to your composer.json:, (*7)

{
    "require": {
        "hemeragestao/money": "dev-master"
    },
    "minimum-stability": "dev"    
}

Now run the install command., (*8)

$ composer.phar install

Added Features

This fork replaces the maping of currencies from a simple ISO 4217 map from openexchangerates.org with the data contained in Ruby's Money mapping. This allows for a few additional features, including generating formatted output string for the Money objects. Also, the Money object constructor takes a float parameter, using it as the amount instead of units. This will be changed on later releases., (*9)

<?php

use Money\Money;

echo Money::EUR(5.32)->formattedString();

Output:, (*10)

€ 5.32

Integration

See MoneyBundle or [TbbcMoneyBundle][4] for Symfony integration., (*11)

The Versions

06/02 2014

dev-master

9999999-dev http://verraes.net/2011/04/fowler-money-pattern-in-php/

Fork of Mathias Verraes PHP implementation of Fowler's Money pattern

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Gustavo Santos

money value object generic sub-domain

13/04 2013

dev-zero-equality

dev-zero-equality http://verraes.net/2011/04/fowler-money-pattern-in-php/

PHP implementation of Fowler's Money pattern

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

money value object generic sub-domain

13/04 2013

1.2.0

1.2.0.0 http://verraes.net/2011/04/fowler-money-pattern-in-php/

PHP implementation of Fowler's Money pattern

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

money value object generic sub-domain

03/08 2012

1.1.0

1.1.0.0 http://blog.verraes.net/2011/04/fowler-money-pattern-in-php/

PHP implementation of Fowler's Money pattern

  Sources   Download

MIT

money value object generic sub-domain