Get support for garak/money-bundle
If you're new to LTH, please see our FAQ for more information on what it is we do.
Support Options
Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:
View Open IssuesTake a look to see if anyone else has experienced the same issue as you and if they managed to solve it.
Open an IssueMake sure to read any relevant guidelines for opening issues on this repo before posting a new issue.
Sponsor directlyCheck out the page and see if there are any options to sponsor this project or it's developers directly.
garak/money-bundle
Money bundle
The purpose of this bundle is very simple: 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 just use "money" as 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 being not nullable). You're done: your property will be mapped to a Money EUR object (see below for customizations).
Installation
Execute composer require garak/money-bundle
.
Mapping example
<?php
namespace App\Entity;
use Money\Money;
class Foo
{
public __construct(
public int $id,
public \DateTimeImmutable $date,
public ?string $notes,
public Money $payment,
) {
}
}
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://doctrine-project.org/schemas/orm/doctrine-mapping https://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>
<entity name="App\Entity\Foo">
<id name="id"/>
<field name="date" type="date_immutable"/>
<field name="notes" type="text" length="65535" nullable="true"/>
<field name="payment" type="money"/>
</entity>
</doctrine-mapping>
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 currencties) - cast the submitted value to integer, which is the format expected by
moneyphp/money
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 in the database is 5099, this will display "€50,99" #}
{{ foo.payment|money }}
Customizations
You can use a currency different from EUR. Also, you can customize the separators used by the Twig extension, and have the symbol after the amount:
money:
currency: CHF # default "EUR"
decimal: "." # default ","
thousands: "," # default "."
after: true # default false
Our Mission
We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.
From the Blog
Interesting Articles
-
Generating income from open source
Jun 23 • 8 min read
-
2023 State of OSS
Apr 23 • 45 min read ★
-
A funding experiment...
Aug 19 • 10 min read
-
But You Said I could
Aug 19 • 2 min read
Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated
p-e622a1a2