Files
chill-bundles/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadCountries.php
Julie Lenaerts 895e1be9ef Fix fixtures
- Inject parameters directly instead of getting from container
- User PasswordHasher instead of EncoderFactory
- set parameters directly and correctly encode values to json
2025-09-11 11:44:53 +02:00

50 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\DataFixtures\ORM;
use Chill\MainBundle\Command\LoadCountriesCommand;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
/**
* Load countries into database.
*/
class LoadCountries extends Fixture implements OrderedFixtureInterface
{
private array $availableLanguages;
public function __construct(private readonly ParameterBagInterface $parameterBag)
{
$this->availableLanguages = $this->parameterBag->get('chill_main.available_languages');
}
public function getOrder(): int
{
return 20;
}
public function load(ObjectManager $manager): void
{
echo "loading countries... \n";
$languages = $this->availableLanguages;
foreach (LoadCountriesCommand::prepareCountryList($languages) as $country) {
$manager->persist($country);
}
$manager->flush();
}
}