Ejemplo n.º 1
0
 public function initialize(Config $config, $directory, $filenameWithDate = false)
 {
     $this->setFilename($config, $directory, $filenameWithDate);
     $this->csvWriter = new CsvWriter($config->getCsvDialect() ?: Dialect::createExcelDialect());
     $this->csvWriter->open($this->filename);
     $this->hasHeader = false;
 }
Ejemplo n.º 2
0
 /**
  * 
  * @param FakerConfig $fakerConfig
  */
 public function __construct(FakerConfig $fakerConfig = null)
 {
     parent::__construct([]);
     $this->setLocale(FakerConfig::DEFAULT_LOCALE);
     $this->generateSeed();
     $this->setMaxTimestamp('now');
     $this->csvDialect = Dialect::createExcelDialect();
     if ($fakerConfig) {
         $this->setFakerConfig($fakerConfig);
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $app = $this->getApplication()->getSilex();
     $outputDir = realpath(is_dir($input->getArgument('output-dir')) ? $input->getArgument('output-dir') : '.');
     $format = $input->getOption('format');
     if (!in_array($format, array('json', 'xml'))) {
         throw new \InvalidArgumentException('The format ' . $format . ' is not allowed.');
     }
     $config = new Config();
     $config->setClassName('Entity\\User')->setFakeNumber(100)->setFormats(array_keys(DumpManager::getAvailableFormats()))->setLocale('en_US')->setSeed(17846134)->setCsvDialect(Dialect::createExcelDialect())->setVariables([new Variable('firstname', 'firstName'), new Variable('lastname', 'lastName'), new Variable('emailDomain', 'freeEmailDomain'), new Variable('birthday', 'dateTimeBetween', ['Y-m-d', '1970-01-01', '2014-01-01']), new Variable('phonehome', 'phoneNumber'), new Variable('phonework', 'phoneNumber'), new Variable('phonemobile', 'phoneNumber'), new Variable('street1', 'streetAddress'), new Variable('city1', 'city'), new Variable('postalcode1', 'postcode'), new Variable('country1', 'country'), new Variable('street2', 'streetAddress'), new Variable('city2', 'city'), new Variable('postalcode2', 'postcode'), new Variable('country2', 'country')])->setColumns([new Column('firstname', '%firstname%', 'capitalize'), new Column('lastname', '%lastname%', 'capitalize'), new Column('email', '%firstname%.%lastname%@%emailDomain%', 'lowercase'), new Column('birthday', '%birthday%'), new Column('address', null, null, [new Column('home', null, null, [new Column('street', '%street1%', 'capitalize'), new Column('city', '%city1%', 'capitalize'), new Column('postalcode', '%postalcode1%'), new Column('country', '%country1%', 'capitalize')]), new Column('work', null, null, [new Column('street', '%street2%', 'capitalize'), new Column('city', '%city2%', 'capitalize'), new Column('postalcode', '%postalcode2%'), new Column('country', '%country2%', 'capitalize')])]), new Column('phone', null, null, [new Column('home', '%phonehome%'), new Column('mobile', '%phonemobile%')])]);
     $serializer = $app['fakery.config_serializer'];
     $configFile = $serializer->dump($config, $outputDir, $format);
     $output->writeln('Example Config file dumped to <info>' . $configFile) . '</info>';
 }