Download the PHP package cocolabs-sas/currency-bundle without Composer
On this page you can find all versions of the php package cocolabs-sas/currency-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cocolabs-sas/currency-bundle
More information about cocolabs-sas/currency-bundle
Files in cocolabs-sas/currency-bundle
Package currency-bundle
Short Description This Symfony2 bundle provide a service and a Twig extension to convert and display currencies. It is a fork of lexik/currency-bundle
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:
Additional 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 CurrencyAdapter)
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:
All versions of currency-bundle with dependencies
ext-curl Version *
ext-intl Version *
ext-json Version *
ext-simplexml Version *
symfony/config Version ^4.0|^5.0
symfony/console Version ^4.0|^5.0
symfony/dependency-injection Version ^4.0|^5.0
symfony/framework-bundle Version ^4.0|^5.0
symfony/validator Version ^4.0|^5.0
twig/twig Version ^v2.14