Exemplo n.º 1
0
 public function testFileFactory()
 {
     # virtualFile
     $vfile = FileFactory::create('string://' . $this->str);
     $this->assertInstanceOf('\\Faker\\Parser\\VFile', $vfile);
     $file = FileFactory::create('text.xml');
     $this->assertInstanceOf('\\Faker\\Parser\\File', $file);
 }
Exemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     # get the di container
     $project = $this->getApplication()->getProject();
     #event manager
     $event = $project['event_dispatcher'];
     # fetch the schema parser
     $parser = $project->getXMLEngineParser();
     $parser->register();
     # fetch the file and verify the path
     $schema_file = $input->getArgument('schema');
     $source_io = $project['source_io'];
     if ($source_io->exists($schema_file) === false) {
         throw new \RuntimeException("File {$schema_file} not found under /source");
     }
     $file = $source_io->load($schema_file, '', true);
     # bind build events output handler
     $event->addSubscriber(new BuilderConsoleOutput($event, $output));
     $output->writeln('<info>Starting Generator</info>');
     # is file php or xml
     if (pathinfo($file->getFilename(), PATHINFO_EXTENSION) == 'xml') {
         # parse the schema file
         $builder = $parser->parse(FileFactory::create($file->getPathname()), new ParseOptions());
         # fetch the composite
         $composite = $builder->build();
     } else {
         # try load a php file
         $composite = (include $file->getPathname());
     }
     # check if we use the debug or normal notifier
     if ($input->getOption('verbose')) {
         $event->addSubscriber(new DebugOutputter($output));
     } elseif ($composite instanceof SchemaNode) {
         # use the composite to calculate number of rows
         $rows = 0;
         foreach ($composite->getChildren() as $table) {
             if ($table instanceof TableNode) {
                 $rows += $table->getRowsToGenerate();
             }
         }
         # instance zend_progress bar
         $console_adapter = new ZendConsoleAdapter();
         $console_adapter->setElements(array(ZendConsoleAdapter::ELEMENT_PERCENT, ZendConsoleAdapter::ELEMENT_BAR, ZendConsoleAdapter::ELEMENT_TEXT));
         $progress_bar = new ProgressBar($console_adapter, 1, $rows, null);
         # instance the default notifier
         $event->addSubscriber(new ProgressBarOutputter($event, $progress_bar));
     }
     # start execution of the generate
     $result = array();
     if ($composite instanceof GeneratorInterface) {
         $composite->generate(1, $result, array());
     } else {
         throw new \RuntimeException('No Composite with GeneratorInterface found');
     }
 }
Exemplo n.º 3
0
 function getFormat($filename)
 {
     $options = new ParseOptions();
     $fp = FileFactory::create($filename);
     $data = "";
     $format_base_type = FALSE;
     do {
         $data .= $fp->fread(64);
         $nlpos = strpos($data, "\n");
         $length = strlen($data);
     } while ($length < 1024 && !$nlpos && !$fp->feof());
     $fp->fclose();
     unset($fp);
     if ($nlpos) {
         $data = substr($data, 0, $nlpos);
     }
     $data = ltrim($data);
     if ($data[0] == "<") {
         $format_base_type = "xml";
     }
     if (strpos($data, "?xml")) {
         $format_base_type = "xml";
     }
     //set csv as the default
     if ($format_base_type === FALSE) {
         $format_base_type = "csv";
     }
     $options->setParser($format_base_type);
     $analysis_function = '\\Faker\\Parser\\Analysis\\' . strtoupper($format_base_type);
     if (class_exists($analysis_function)) {
         $fp = FileFactory::create($filename);
         $class = new $analysis_function($this->dispatcher);
         $format_parameters = $class->analyse($fp, $options);
     } else {
         throw new AnalysisClassNotFound($analysis_function);
     }
     return $format_parameters;
 }