Download the PHP package matmar10/money-bundle without Composer
On this page you can find all versions of the php package matmar10/money-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download matmar10/money-bundle
More information about matmar10/money-bundle
Files in matmar10/money-bundle
Package money-bundle
Short Description A series of money related utility classes wrapping integer math and money fractional allocation.
License Apache
Informations about the package money-bundle
Money Bundle
MAINTAINER WANTER - issue reports and pull requests will not be actively investigated. I am happy to advise, but I'm not longer actively using/maintaing this library. Please let me know if you're interested in taking over ownership of the repo.
Overview
Symfony2 Bundle wrapping common Money and Currency related needs such as integer-based math, currency codes, and money conversion.
Installation
Add the package to your composer.json file:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/matmar10/money-bundle
}
],
"require": {
"matmar10/money-bundle": "dev-master"
}
}
Creating Objects
Currencies are identified by a currency code and have a calculation and display precision:
Basic Math
The Money object wraps all basic math functions using underlying integer math to avoid the (problems with floating point math)[http://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency].
All amounts are stored as integer values internally using the calculation precision as the scale.
Dealing with Fractional Cents
How do you divide $10 evenly amongst three people? In reality, you can't divide fractional cents.
Really, you want to end up with three equal-ish shares:
- $3.34
- $3.33
- $3.33
Converting Between Currencies
Use the CurrencyPair
object to convert between disparate currencies using an exchange rate:
Note that the rate works bi-directionally:
Currency Manager Service
Instead of building up currencies and money objects manually all the time,
consider using the lmh_money.currency_manager
service that is registered
into Symfony's dependency injection container.
The manager supports providing an ISO country or currency code:
Adding New Currencies
You can add new currencies that are not supported by default. This is useful, for example to add alternative currencies such as Litecoin and Ripple
Currency Alias
Alias handling for currencies, to set the currency settings "Euro" equel to "EUR", extend the config like this:
Currency Validator
The Bundle also includes a Symfony validator for use in validating an entity's attribute is a valid currency code using (Symfony's Validator component)[https://github.com/symfony/Validator].
Example use of the annotation:
Using in the validator (see (Validator Component docs for details)[https://github.com/symfony/Validator] ):
Embedded Money object in a Doctrine Entity
Money object is prepared to handle doctrine embedded style: http://doctrine-orm.readthedocs.org/en/latest/tutorials/embeddables.html
Add this to your config:
Inside your entity:
your table should now these two new columns:
- price_amount // price as INTEGER value
- price_currency // currency code like "EUR"
All versions of money-bundle with dependencies
symfony/framework-bundle Version 2.4.*
doctrine/orm Version *
jms/serializer Version ~0.15
jms/aop-bundle Version ~1.0
matmar10/lib-money Version ~1.0.2