Ejemplo n.º 1
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');
     }
 }
Ejemplo n.º 2
0
 public function testSetInvalidFinishAction()
 {
     try {
         $adapter = new Adapter\Console();
         $adapter->setFinishAction('CUSTOM_FINISH_ACTION');
         $this->fail('Expected Zend_ProgressBar_Adapter_Exception');
     } catch (Adapter\Exception $e) {
         $this->assertEquals($e->getMessage(), 'Invalid finish action specified');
     }
 }
Ejemplo n.º 3
0
 public function testSetInvalidFinishAction()
 {
     $adapter = new Adapter\Console();
     
     $this->setExpectedException('Zend\ProgressBar\Adapter\Exception\InvalidArgumentException','Invalid finish action specified');
     $adapter->setFinishAction('CUSTOM_FINISH_ACTION');
 }
Ejemplo n.º 4
0
    #Setup console ouput to list to build events
    $event->addSubscriber(new Faker\Components\Engine\Common\Output\BuilderConsoleOutput($event, $output));
    $output->writeln('<info>Starting Generator</info>');
    # command only supports php builder and Entity Builder.
    $composite = (include $splFileInfo->getRealPath());
    # if none returned from php file must be an entity generator
    if ($composite !== null) {
        # 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();
        $composite->generate(1, $result);
    }
    $output->writeln(sprintf("%s <info>success</info>", 'faker:run'));
});
//---------------------------------------------------------------
// Run the console
//
//--------------------------------------------------------------
$console->run();