Download the PHP package garak/money-bundle without Composer
On this page you can find all versions of the php package garak/money-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package money-bundle
Money bundle
The purpose of this bundle is straightforward: using the moneyphp/money
library with a single currency.
The typical use is when you need to map an amount of money to a database field. You could embed the Money object in your entity, but this is not perfectly working, because Doctrine doesn't support nullable embeddable objects.
Moreover, you probably want to use a single currency in your project, so you don't want to use a useless column for the currency itself.
With this bundle, you can use "money" as a type. It's up to you to choose if your property is nullable or not (as for any other Doctrine mapping, the default option is not nullable). You're done: your property will be mapped to a Money EUR object (see below for customisations).
Installation
Execute composer require garak/money-bundle
.
Mapping example
Form type extension
This bundle configures a form type extension for the Symfony MoneyType, which does two things:
- set the default option of
divisor
to100
(which should be the value to use with most currencies) - cast the submitted value to an integer, which is the format expected by
moneyphp/money
. The submitted value can be cast directly to aMoney
object by configuring the bundle optionmoney_transform
to true
You don't need to do anything to use this extension, which is automatically applied.
Twig extension
This bundle exposes a Twig filter called money
. It's useful to format the value of your money property.
Example:
If the value is nullable, you can use the nullable_money
filter instead:
Customizations
You can use a currency different from EUR.
Also, you can customise the separators used by the Twig extension, and have the symbol after the amount
(with a space, if you want). Finally, you can enable the transformation of the submitted value to a Money
object in the form type extension.
Here's an example of a configuration file:
All versions of money-bundle with dependencies
doctrine/dbal Version ^3.2 || ^4.0
moneyphp/money Version ^3.0 || ^4.0
symfony/config Version ^5.4 || ^6.0 || ^7.0
symfony/dependency-injection Version ^5.4 || ^6.4 || ^7.0
symfony/form Version ^5.4 || ^6.4 || ^7.0
symfony/http-kernel Version ^5.4 || ^6.4 || ^7.0
twig/twig Version ^3.4