Download the PHP package fadion/fixerio without Composer
On this page you can find all versions of the php package fadion/fixerio. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package fixerio
Thin wrapper for Fixer.io
A thin wrapper for Fixer.io, a service for foreign exchange rates and currency conversion. It provides a few methods to easily construct the url, makes the api call and gives back the response.
Installation
- Add the package to your composer.json file and run
composer update
:
Laravel users can use the Facade for even easier access.
- Add
Fadion\Fixerio\ExchangeServiceProvider::class
to yourconfig/app.php
file, inside theproviders
array. - Add a new alias:
'Exchange' => Fadion\Fixerio\Facades\Exchange::class
to yourconfig/app.php
file, inside thealiases
array.
Usage
Let's get the rates of EUR and GBP with USD as the base currency:
By default, the base currency is EUR
, so if that's your base, there's no need to set it. The symbols can be omitted too, as Fixer will return all the supported currencies.
A simplified example without the base and currency:
The historical
option will return currency rates for every day since the date you've specified. The base currency and symbols can be omitted here to, but let's see a full example:
Finally, you may have noticed the use of the Currency
class with currencies as constants. It's just a convenience to prevent errors from typos, but they're completely optional.
This:
is equivalent to:
Use whatever method fills your needs.
Response
The response is a simple array with currencies as keys and ratios as values. For a request like the following:
the response will be an array:
which you can access with the keys as strings or using the currency constants:
There is an option to handle the response as an object:
The last option is to return the response as a Result
class. This allows access to the full set of properties returned from the feed.
Error Handling
To handle errors, the package provides 2 exceptions. ConnectionException
when http requests go wrong and ResponseException
when the returned response from the api is not as expected. An example with exception handling:
Laravel Usage
Nothing changes for Laravel apart from the Facade. It's just a convenience for a tad shorter way of using the package:
To use this Facade, you should set your access key in your config/services.php
file: