PHP code example of pavlepredic / currency-converter
1. Go to this page and download the library: Download pavlepredic/currency-converter 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/ */
pavlepredic / currency-converter example snippets
namespace AppBundle\Repository;
use AppBundle\Entity\ExchangeRate;
use Doctrine\ORM\EntityRepository;
use PavlePredic\CurrencyConverter\Entity\ExchangeRateInterface;
use PavlePredic\CurrencyConverter\Repository\ExchangeRateRepositoryInterface;
class ExchangeRateRepository extends EntityRepository implements ExchangeRateRepositoryInterface
{
/**
* @param string $sourceCurrency
* @param array $destinationCurrencies
* @return ExchangeRateInterface[]
*/
public function findAllBySourceCurrencyAndDestinationCurrencies($sourceCurrency, array $destinationCurrencies)
{
return $this->findBy([
'sourceCurrency' => $sourceCurrency,
'destinationCurrency' => $destinationCurrencies,
]);
}
/**
* @param string $sourceCurrency
* @param string $destinationCurrency
* @return ExchangeRateInterface
*/
public function findOneBySourceCurrencyAndDestinationCurrency($sourceCurrency, $destinationCurrency)
{
return $this->findOneBy([
'sourceCurrency' => $sourceCurrency,
'destinationCurrency' => $destinationCurrency,
]);
}
/**
* @param string $sourceCurrency
* @param string $destinationCurrency
* @param float $rate
* @return ExchangeRateInterface
*/
public function update($sourceCurrency, $destinationCurrency, $rate)
{
$exchangeRate = $this->findOneBySourceCurrencyAndDestinationCurrency($sourceCurrency, $destinationCurrency);
if (!$exchangeRate) {
$exchangeRate = ExchangeRate::create($sourceCurrency, $destinationCurrency, $rate);
$this->getEntityManager()->persist($exchangeRate);
}
$exchangeRate->setRate($rate);
return $exchangeRate;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.