resources
5 years ago
src
2 years ago
CHANGELOG.md
2 years ago
LICENSE
6 years ago
README.md
5 years ago
composer.json
2 years ago
README.md
115 lines
| 1 | # Money |
| 2 | |
| 3 | [](https://github.com/moneyphp/money/releases](https://github.com/moneyphp/money/releases](https://github.com/moneyphp/money/releases) |
| 4 |  |
| 5 | [](https://packagist.org/packages/moneyphp/money](https://packagist.org/packages/moneyphp/money](https://packagist.org/packages/moneyphp/money) |
| 6 | |
| 7 | [](mailto:team@moneyphp.org](mailto:team@moneyphp.org](mailto:team@moneyphp.org) |
| 8 | |
| 9 |  |
| 10 | |
| 11 | PHP library to make working with money safer, easier, and fun! |
| 12 | |
| 13 | > "If I had a dime for every time I've seen someone use FLOAT to store currency, I'd have $999.997634" -- [](https://twitter.com/billkarwin/status/347561901460447232Bill Karwin](https://twitter.com/billkarwin/status/347561901460447232](https://twitter.com/billkarwin/status/347561901460447232) |
| 14 | |
| 15 | In short: You shouldn't represent monetary values by a float. Wherever |
| 16 | you need to represent money, use this Money value object. Since version |
| 17 | 3.0 this library uses [](https://github.com/moneyphp/money/pull/136strings internally](https://github.com/moneyphp/money/pull/136](https://github.com/moneyphp/money/pull/136) |
| 18 | in order to support unlimited integers. |
| 19 | |
| 20 | ```php |
| 21 | <?php |
| 22 | |
| 23 | use Money\Money; |
| 24 | |
| 25 | $fiveEur = Money::EUR(500); |
| 26 | $tenEur = $fiveEur->add($fiveEur); |
| 27 | |
| 28 | list($part1, $part2, $part3) = $tenEur->allocate([1, 1, 1]); |
| 29 | assert($part1->equals(Money::EUR(334))); |
| 30 | assert($part2->equals(Money::EUR(333))); |
| 31 | assert($part3->equals(Money::EUR(333))); |
| 32 | ``` |
| 33 | |
| 34 | The documentation is available at http://moneyphp.org |
| 35 | |
| 36 | |
| 37 | ## Requirements |
| 38 | |
| 39 | PHP 5.6+. Other than that, this library has no external requirements. MoneyPHP will not provide any support to |
| 40 | PHP versions that are [](http://php.net/supported-versions.phpnot supported by the language itself](http://php.net/supported-versions.php](http://php.net/supported-versions.php). There might be |
| 41 | additional dependencies for specific feature, e.g. the Swap exchange implementation, check the documentation for more information. |
| 42 | |
| 43 | |
| 44 | ## Install |
| 45 | |
| 46 | Via Composer |
| 47 | |
| 48 | ```bash |
| 49 | $ composer require moneyphp/money |
| 50 | ``` |
| 51 | |
| 52 | |
| 53 | ## Features |
| 54 | |
| 55 | - JSON Serialization |
| 56 | - Big integer support utilizing different, transparent calculation logic upon availability (bcmath, gmp, plain php) |
| 57 | - Money formatting (including intl formatter) |
| 58 | - Currency repositories (ISO currencies included) |
| 59 | - Money exchange (including [](http://swap.voutzinos.orgSwap](http://swap.voutzinos.org](http://swap.voutzinos.org) implementation) |
| 60 | |
| 61 | |
| 62 | ## Documentation |
| 63 | |
| 64 | Please see the [](http://moneyphp.orgofficial documentation](http://moneyphp.org](http://moneyphp.org). |
| 65 | |
| 66 | |
| 67 | ## Testing |
| 68 | |
| 69 | We try to follow BDD and TDD, as such we use both [](http://www.phpspec.netphpspec](http://www.phpspec.net](http://www.phpspec.net) and [](https://phpunit.dephpunit](https://phpunit.de](https://phpunit.de) to test this library. |
| 70 | |
| 71 | ```bash |
| 72 | $ composer test |
| 73 | ``` |
| 74 | |
| 75 | ### Running the tests in Docker |
| 76 | |
| 77 | Money requires a set of dependencies, so you might want to run it in Docker. |
| 78 | |
| 79 | First, build the image locally: |
| 80 | |
| 81 | ```bash |
| 82 | $ docker build -t moneyphp . |
| 83 | ``` |
| 84 | |
| 85 | Then run the tests: |
| 86 | |
| 87 | ```bash |
| 88 | $ docker run --rm -it -v $PWD:/app -w /app moneyphp vendor/bin/phpunit --exclude-group segmentation |
| 89 | ``` |
| 90 | |
| 91 | |
| 92 | ## Contributing |
| 93 | |
| 94 | We would love to see you helping us to make this library better and better. |
| 95 | Please keep in mind we do not use suffixes and prefixes in class names, |
| 96 | so not `CurrenciesInterface`, but `Currencies`. Other than that, Style CI will help you |
| 97 | using the same code style as we are using. Please provide tests when creating a PR and clear descriptions of bugs when filing issues. |
| 98 | |
| 99 | |
| 100 | ## Security |
| 101 | |
| 102 | If you discover any security related issues, please contact us at [](mailto:team@moneyphp.orgteam@moneyphp.org](mailto:team@moneyphp.org](mailto:team@moneyphp.org). |
| 103 | |
| 104 | |
| 105 | ## License |
| 106 | |
| 107 | The MIT License (MIT). Please see [](LICENSELicense File](LICENSE](LICENSE) for more information. |
| 108 | |
| 109 | |
| 110 | ## Acknowledgements |
| 111 | |
| 112 | This library is heavily inspired by [](http://martinfowler.com/eaaCatalog/money.htmlMartin Fowler's Money pattern](http://martinfowler.com/eaaCatalog/money.html](http://martinfowler.com/eaaCatalog/money.html). |
| 113 | A special remark goes to [](https://github.com/mathiasverraesMathias Verraes](https://github.com/mathiasverraes](https://github.com/mathiasverraes), without his contributions, |
| 114 | in code and via his [](http://verraes.net/#blogblog](http://verraes.net/#blog](http://verraes.net/#blog), this library would not be where it stands now. |
| 115 |