Download the PHP package lexik/currency-bundle without Composer
On this page you can find all versions of the php package lexik/currency-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lexik/currency-bundle
More information about lexik/currency-bundle
Files in lexik/currency-bundle
Package currency-bundle
Short Description This Symfony2 bundle provide a service and a Twig extension to convert and display currencies.
License MIT
Homepage https://github.com/lexik/LexikCurrencyBundle
Informations about the package currency-bundle
Overview
This Symfony2 bundle provide a service and a twig extension to convert and display currencies.
Installation
Add the bunde to your composer.json
file:
As of version 1.2.0
, currency_format
does not convert the currency anymore, it only formats the given value according to the locale. If you need to convert and format a value, please use currency_convert_format
filter.
Then run a composer update:
Register the bundle with your kernel:
Configuration
Minimun configuration:
Additonal options (default values are shown here):
Initialize currencies
To initialize the currencies rate in the database run the following command:
Example by using the ECB adapter, to get rates from the European Central Bank.
In the command line ecb
is the value returned by the getIdentifier()
method of the adapter class.
Usage
Currency conversion service
Use the convert()
method from the lexik_currency.converter
service:
Retrieve managed configurations
In the controller, you can use the following line to retrieve an array of all managed currencies:
Twig filters
The bundle provide 3 filters to convert and format a value:
currency_convert
: convert a value.currency_format
: format a value according to the current locale.currency_convert_format
: convert and format a value.
Here an example with the currency_convert_format
filter.
You can also pass more arguments, to display or not decimal and the currency symbol. And you can specify the amount's currency if needed.
Load conversions rate from another source (custom CurrencyAdatpter)
If you need to load conversions rates from another source you will have to create a CurrencyAdatpter and set it as the default adapter.
To create your custom adapter you will have to extend Lexik\Bundle\CurrencyBundle\Adapte\AbstractCurrencyAdapter
which define 2 abstract methods:
- getIdentifier(): returns the identifier of the adapter.
- attachAll(): loads the currencies with their rate (this method is call from the import command to get all currencies to save in the database).
Here an example
Then define the adapter as a service, don't forget the lexik_currency.adapter
tag:
And import the currencies by using your adapter: