PHP code example of bambamboole / tools

1. Go to this page and download the library: Download bambamboole/tools library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bambamboole / tools example snippets


use Bambamboole\Tools\ToolManager;

$tools = new ToolManager();

// VAT rates for a country (TEDB)
$rates = $tools->taxRates()->getTaxRates('DE');

// Validate a VAT id (VIES)
$result = $tools->vatId()->validate('DE123456789');
$result->valid; // bool

// ECB euro reference rates, latest or historical
$day = $tools->exchangeRates()->getExchangeRates();
$day->rate('USD'); // BigDecimal

$day = $tools->exchangeRates()->getExchangeRates(new DateTimeImmutable('2020-03-13'));

// Convert money, incl. cross rates via EUR
use Brick\Math\RoundingMode;
use Brick\Money\Money;

$converter = $tools->currencyConverter();
$converter->convert(Money::of(100, 'USD'), 'GBP', roundingMode: RoundingMode::HalfEven);

use Illuminate\Cache\ArrayStore;
use Illuminate\Cache\Repository;

$cache = new Repository(new ArrayStore());
$rates = $tools->exchangeRates($cache)->getExchangeRates();

public function __construct(
    private readonly Bambamboole\Tools\ExchangeRates\ExchangeRatesClient $exchangeRates,
    private readonly Brick\Money\CurrencyConverter $converter,
) {}

use Tools;

Tools::taxRates()->getTaxRates('DE');
Tools::vatId()->validate('DE123456789');
Tools::exchangeRates()->getExchangeRates();
Tools::currencyConverter()->convert(...);