PHP code example of intechventures / seed-bundle
1. Go to this page and download the library: Download intechventures/seed-bundle 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/ */
intechventures / seed-bundle example snippets
namespace AcmeBundle\ISOBundle\Seeds;
use Soyuka\SeedBundle\Command\Seed;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Parser;
use AcmeBundle\ISOBundle\Entity\Country;
class CountrySeed extends Seed
{
protected function configure()
{
//The seed won't load if this is not set
//The resulting command will be {prefix}:country
$this
->setSeedName('country');
parent::configure();
}
public function load(InputInterface $input, OutputInterface $output){
//Doctrine logging eats a lot of memory, this is a wrapper to disable logging
$this->disableDoctrineLogging();
//Access doctrine through $this->doctrine
$countryRepository = $this->doctrine->getRepository('AcmeISOBundle:Country');
$yaml = new Parser();
//for example, using umpirsky/country-list (lazy yaml)
$countries = $yaml->parse(file_get_contents('vendor/umpirsky/country-list/country/cldr/fr/country.yaml'));
foreach ($countries as $id => $country) {
if($countryRepository->findOneById($id)) {
continue;
}
$e = new Country();
$e->setId($id);
$e->setName($country);
//Doctrine manager is also available
$this->manager->persist($e);
$this->manager->flush();
}
$this->manager->clear();
}
public function getOrder() {
return 0;
}
}