feat: add currency lister
feat: add currency lister static currency lister
This commit is contained in:
parent
53eeb4b373
commit
e89290473b
@ -4,6 +4,8 @@
|
||||
# Put parameters here that don't need to change on each machine where the app is deployed
|
||||
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
|
||||
parameters:
|
||||
env(SYMFONY_EXAMPLE_APP_CURRENCIES): '["CZK", "EUR", "USD", "GBP"]'
|
||||
app.currencies: '%env(json:SYMFONY_EXAMPLE_APP_CURRENCIES)%'
|
||||
|
||||
services:
|
||||
# default configuration for services in *this* file
|
||||
@ -21,5 +23,10 @@ services:
|
||||
- '../src/Entity/'
|
||||
- '../src/Kernel.php'
|
||||
|
||||
App\Service\StaticCurrencyLister:
|
||||
arguments:
|
||||
$available_currencies: '%app.currencies%'
|
||||
|
||||
App\Service\CurrencyListerInterface: '@App\Service\StaticCurrencyLister'
|
||||
# add more service definitions when explicit configuration is needed
|
||||
# please note that last definitions always *replace* previous ones
|
||||
|
12
src/Service/CurrencyListerInterface.php
Normal file
12
src/Service/CurrencyListerInterface.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
interface CurrencyListerInterface
|
||||
{
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCurrencies(): iterable;
|
||||
}
|
20
src/Service/StaticCurrencyLister.php
Normal file
20
src/Service/StaticCurrencyLister.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
/**
|
||||
* Represents currency lister loaded from configuration
|
||||
*/
|
||||
readonly final class StaticCurrencyLister implements CurrencyListerInterface {
|
||||
/**
|
||||
* @param String[] $available_currencies
|
||||
*/
|
||||
public function __construct(private array $available_currencies) {
|
||||
}
|
||||
|
||||
public function getCurrencies(): iterable
|
||||
{
|
||||
return $this->available_currencies;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user