|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace App\DataFixtures; |
|
6
|
|
|
|
|
7
|
|
|
use App\Entity\Currency; |
|
8
|
|
|
use Doctrine\Bundle\FixturesBundle\Fixture; |
|
9
|
|
|
use Doctrine\Persistence\ObjectManager; |
|
10
|
|
|
|
|
11
|
|
|
final class CurrencyFixtures extends Fixture |
|
12
|
|
|
{ |
|
13
|
|
|
public function load(ObjectManager $manager): void |
|
14
|
|
|
{ |
|
15
|
|
|
foreach ($this->getCurrencyData() as [$currencyTitle, $code, $symbolLeft, $symbolRight]) { |
|
16
|
|
|
$currency = new Currency(); |
|
17
|
|
|
$currency->setCurrencyTitle($currencyTitle); |
|
18
|
|
|
$currency->setCode($code); |
|
19
|
|
|
$currency->setSymbolLeft($symbolLeft); |
|
20
|
|
|
$currency->setSymbolRight($symbolRight); |
|
21
|
|
|
|
|
22
|
|
|
$manager->persist($currency); |
|
23
|
|
|
$this->addReference($code, $currency); |
|
24
|
|
|
} |
|
25
|
|
|
$manager->flush(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
private function getCurrencyData(): array |
|
29
|
|
|
{ |
|
30
|
|
|
return [ |
|
31
|
|
|
// $currencyData = [$currencyTitle, $code, $symbolLeft, $symbolRight]; |
|
32
|
|
|
['US Dollar', 'USD', '$', ''], |
|
33
|
|
|
['Euro', 'EUR', '', '€'], |
|
34
|
|
|
['Pound Sterling', 'GBP', '£', ''], |
|
35
|
|
|
['Hong Kong Dollar', 'HKD', 'HK$', ''], |
|
36
|
|
|
['Russian Ruble', 'RUB', '₽', ''], |
|
37
|
|
|
['Belarusian ruble', 'BYN', '', 'Br'], |
|
38
|
|
|
]; |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|