2017 © Pedro Peláez
 

library money

PHP implementation of Fowler's Money pattern

image

srtfisher/money

PHP implementation of Fowler's Money pattern

  • Sunday, August 24, 2014
  • by srtfisher
  • Repository
  • 0 Watchers
  • 0 Stars
  • 23 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 226 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Money

Build Status, (*1)

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

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

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

<?php

use Money\Money;

$fiveEur = Money::Euro(500);
$tenEur = $fiveEur->add($fiveEur);

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

// Format
// $1,234.56
echo Money::USD(123456)->format();

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

Money Format

When creating a money object, it is expected to be in the lowest value of the currency (e.g. cents). For example, $1,234.56 is actually 123,456 cents., (*6)

For conversion from cents to dollars:, (*7)

<?php
$dollars = $cents * 100;

For conversion from dollars to cents:, (*8)

<?php
$cents = $dollars / 100;

Installation

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

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

Now run the install command., (*10)

$ composer.phar install

Integration

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

The Versions

24/08 2014

dev-master

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

PHP implementation of Fowler's Money pattern

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

money ddd value object generic sub-domain domain-driven design

24/08 2014

1.3.0-beta1

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

PHP implementation of Fowler's Money pattern

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

money ddd value object generic sub-domain domain-driven design

22/03 2014

dev-nextrelease

dev-nextrelease 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 ddd value object generic sub-domain domain-driven design

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