74 lines
2.5 KiB
PHP
74 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\DataFixtures;
|
|
|
|
use App\Entity\Car;
|
|
use App\Entity\CarBrand;
|
|
use App\Entity\CarFeature;
|
|
use App\Entity\CarModel;
|
|
use App\Entity\DataValues\FuelType;
|
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
|
use Doctrine\Persistence\ObjectManager;
|
|
|
|
class AppFixtures extends Fixture
|
|
{
|
|
/** @var string[] */
|
|
private const array FEATURES = ['Apple CarPlay', 'Android Auto', 'trekhaak', 'achteruitrijcamera', 'automaat'];
|
|
private const array BRANDS = ['Peugeot', 'Renault', 'Hyundai', 'Seat', 'Nissan', 'MG', 'DS'];
|
|
/** @var array<array<string>> */
|
|
private const array MODELS = [
|
|
['Peugeot', 'E-208', 'electric'],
|
|
['Renault', 'ZOE', 'electric'],
|
|
['Hyundai', 'Kona', 'electric'],
|
|
['Seat', 'Mii Electric', 'electric'],
|
|
['Nissan', 'Leaf', 'electric'],
|
|
['MG', 'MG4', 'electric'],
|
|
['DS', '3 E-Tense', 'electric'],
|
|
];
|
|
|
|
private const array CARS = [
|
|
["N204HV", "E-208", "Borneoplein Groningen"],
|
|
["N094JB", "E-208", "225 Amstelveen"],
|
|
["N590NL", "ZOE", "Villabuurt Groningen"],
|
|
["N958KJ", "Kona", "De Omval Amsterdam"],
|
|
["H623KJ", "Mii Electric", "Breedstraatbuurt Utrecht"],
|
|
["N487NR", "ZOE", "Kruidenwijk Almere"],
|
|
["K799JH", "Kona", "Elandsgrachtbuurt Amsterdam"],
|
|
["XV307X", "Leaf", "Oudwijk Utrecht"],
|
|
["T937DH", "MG4", "Paddewei Barendrecht"],
|
|
["S098SV", "3 E-Tense", "Gelderlandpleinbuurt Amsterdam"],
|
|
];
|
|
|
|
/** @var CarBrand[] */
|
|
private array $brands = [];
|
|
/** @var CarModel[] */
|
|
private array $models = [];
|
|
|
|
public function load(ObjectManager $manager): void
|
|
{
|
|
foreach (self::FEATURES as $featureName) {
|
|
$feature = new CarFeature($featureName);
|
|
$manager->persist($feature);
|
|
}
|
|
|
|
foreach (self::BRANDS as $brandName) {
|
|
$brand = new CarBrand($brandName);
|
|
$this->brands[$brandName] = $brand;
|
|
$manager->persist($brand);
|
|
}
|
|
|
|
foreach (self::MODELS as [$brandName, $modelName, $fuelType]) {
|
|
$model = new CarModel($modelName, FuelType::from($fuelType), $this->brands[$brandName]);
|
|
$this->models[$modelName] = $model;
|
|
$manager->persist($model);
|
|
}
|
|
|
|
foreach (self::CARS as [$registration_plate, $model, $location]) {
|
|
$car = new Car($registration_plate, $location, $this->models[$model]);
|
|
$manager->persist($car);
|
|
}
|
|
|
|
$manager->flush();
|
|
}
|
|
}
|