/**
  * @param Bundle          $bundle     The bundle
  * @param string          $prefix     The prefix
  * @param string          $rootDir    The root directory
  * @param string          $createPage Create data fixtures or not
  * @param OutputInterface $output
  */
 public function generate(Bundle $bundle, $prefix, $rootDir, $createPage, OutputInterface $output)
 {
     $parameters = array('namespace' => $bundle->getNamespace(), 'bundle' => $bundle, 'prefix' => GeneratorUtils::cleanPrefix($prefix));
     $this->generateEntities($bundle, $parameters, $output);
     $this->generateTemplates($bundle, $parameters, $rootDir, $output);
     if ($createPage) {
         $this->generateFixtures($bundle, $parameters, $output);
     }
 }
 /**
  * @param Bundle          $bundle The bundle
  * @param string          $entity
  * @param string          $prefix The prefix
  * @param bool            $dummydata
  * @param OutputInterface $output
  */
 public function generate(Bundle $bundle, $entity, $prefix, $dummydata, OutputInterface $output)
 {
     $parameters = array('namespace' => $bundle->getNamespace(), 'bundle' => $bundle, 'prefix' => GeneratorUtils::cleanPrefix($prefix), 'entity_class' => $entity);
     $this->generateEntities($bundle, $entity, $parameters, $output);
     $this->generateRepositories($bundle, $entity, $parameters, $output);
     $this->generateForm($bundle, $entity, $parameters, $output);
     $this->generateAdminList($bundle, $entity, $parameters, $output);
     $this->generateController($bundle, $entity, $parameters, $output);
     $this->generatePageTemplateConfigs($bundle, $entity, $parameters, $output);
     $this->generateTemplates($bundle, $entity, $parameters, $output);
     $this->generateRouting($bundle, $entity, $parameters, $output);
     $this->generateMenu($bundle, $entity, $parameters, $output);
     $this->generateServices($bundle, $entity, $parameters, $output);
     if ($dummydata) {
         $this->generateFixtures($bundle, $entity, $parameters, $output);
     }
 }
 /**
  * Generate the website.
  *
  * @param BundleInterface $bundle
  * @param string $prefix
  * @param string $rootDir
  * @param bool $demosite
  */
 public function generate(BundleInterface $bundle, $prefix, $rootDir, $demosite = false)
 {
     $this->bundle = $bundle;
     $this->prefix = GeneratorUtils::cleanPrefix($prefix);
     $this->rootDir = $rootDir;
     $this->demosite = $demosite;
     $parameters = array('namespace' => $this->bundle->getNamespace(), 'bundle' => $this->bundle, 'bundle_name' => $this->bundle->getName(), 'prefix' => $this->prefix, 'demosite' => $this->demosite, 'multilanguage' => $this->isMultiLangEnvironment());
     $this->generateControllers($parameters);
     $this->generateAdminLists($parameters);
     $this->generateEntities($parameters);
     $this->generateFormTypes($parameters);
     $this->generateTwigExtensions($parameters);
     $this->generateMenuAdaptors($parameters);
     $this->generateFixtures($parameters);
     $this->generatePagepartConfigs($parameters);
     $this->generatePagetemplateConfigs($parameters);
     $this->generateConfig();
     $this->generateRouting($parameters);
     $this->generateTemplates($parameters);
 }
 /**
  * Asks for the prefix and sets it on the InputInterface as the 'prefix' option, if this option is not set yet.
  * Will set the default to a snake_cased namespace when the namespace has been set on the InputInterface.
  *
  * @param array $text What you want printed before the prefix is asked. If null is provided it'll write a default text.
  * @param string $namespace An optional namespace. If this is set it'll create the default based on this prefix.
  *  If it's not provided it'll check if the InputInterface already has the namespace option.
  *
  * @return string The prefix. But it's also been set on the InputInterface.
  */
 public function askForPrefix(array $text = null, $namespace = null)
 {
     $prefix = $this->input->hasOption('prefix') ? $this->input->getOption('prefix') : null;
     if (is_null($text)) {
         $text = array('', 'You can add a prefix to the table names of the generated entities for example: <comment>projectname_bundlename_</comment>', 'Enter an underscore \'_\' if you don\'t want a prefix.', '');
     }
     while (is_null($prefix)) {
         if (count($text) > 0) {
             $this->output->writeln($text);
         }
         if (is_null($namespace) || empty($namespace)) {
             $namespace = $this->input->hasOption('namespace') ? $this->input->getOption('namespace') : null;
         } else {
             $namespace = $this->fixNamespace($namespace);
         }
         $defaultPrefix = GeneratorUtils::cleanPrefix($this->convertNamespaceToSnakeCase($namespace));
         $question = new Question($this->questionHelper->getQuestion('Tablename prefix', $defaultPrefix), $defaultPrefix);
         $prefix = $this->questionHelper->ask($this->input, $this->output, $question);
         $prefix = GeneratorUtils::cleanPrefix($prefix);
         if ($this->input->hasOption('prefix')) {
             $this->input->setOption('prefix', $prefix);
         }
         if ($prefix == '') {
             break;
         }
         if (!preg_match('/^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*$/', $prefix)) {
             $this->output->writeln(sprintf('<bg=red> "%s" contains invalid characters</>', $prefix));
             $prefix = $text = null;
             continue;
         }
     }
     return $prefix;
 }
 /**
  * @covers Kunstmaan\GeneratorBundle\Helper\GeneratorUtils::cleanPrefix
  */
 public function testSpacesShouldCreateEmptyPrefix()
 {
     $response = GeneratorUtils::cleanPrefix('  ');
     $this->assertEquals(null, $response);
 }
 /**
  * Asks for the prefix and sets it on the InputInterface as the 'prefix' option, if this option is not set yet.
  * Will set the default to a snake_cased namespace when the namespace has been set on the InputInterface.
  *
  * @param array  $text What you want printed before the prefix is asked. If null is provided it'll write a default text.
  * @param string $namespace An optional namespace. If this is set it'll create the default based on this prefix.
  *  If it's not provided it'll check if the InputInterface already has the namespace option.
  *
  * @return string The prefix. But it's also been set on the InputInterface.
  */
 protected function askForPrefix(array $text = null, $namespace = null)
 {
     $prefix = $this->assistant->getOptionOrDefault('prefix', null);
     if (is_null($text)) {
         $text = array('You can add a prefix to the table names of the generated entities for example: ' . '<comment>projectname_bundlename_</comment>', 'Enter an underscore \'_\' if you don\'t want a prefix.', '');
     }
     if (is_null($prefix)) {
         if (count($text) > 0) {
             $this->assistant->writeLine($text);
         }
         if (is_null($namespace) || empty($namespace)) {
             $namespace = $this->assistant->getOption('namespace');
         } else {
             $namespace = $this->fixNamespace($namespace);
         }
         $defaultPrefix = GeneratorUtils::cleanPrefix($this->convertNamespaceToSnakeCase($namespace));
         $prefix = GeneratorUtils::cleanPrefix($this->assistant->ask('Tablename prefix', $defaultPrefix));
         $this->assistant->setOption('prefix', $prefix);
     }
     return $prefix;
 }
 /**
  * Asks for the prefix and sets it on the InputInterface as the 'prefix' option, if this option is not set yet.
  * Will set the default to a snake_cased namespace when the namespace has been set on the InputInterface.
  *
  * @param array  $text What you want printed before the prefix is asked. If null is provided it'll write a default text.
  * @param string $namespace An optional namespace. If this is set it'll create the default based on this prefix.
  *  If it's not provided it'll check if the InputInterface already has the namespace option.
  *
  * @return string The prefix. But it's also been set on the InputInterface.
  */
 public function askForPrefix(array $text = null, $namespace = null)
 {
     $prefix = $this->input->hasOption('prefix') ? $this->input->getOption('prefix') : null;
     if (is_null($text)) {
         $text = array('', 'You can add a prefix to the table names of the generated entities for example: <comment>projectname_bundlename_</comment>', 'Enter an underscore \'_\' if you don\'t want a prefix.', '');
     }
     if (is_null($prefix)) {
         if (count($text) > 0) {
             $this->output->writeln($text);
         }
         if (is_null($namespace) || empty($namespace)) {
             $namespace = $this->input->hasOption('namespace') ? $this->input->getOption('namespace') : null;
         } else {
             $namespace = $this->fixNamespace($namespace);
         }
         $defaultPrefix = GeneratorUtils::cleanPrefix($this->convertNamespaceToSnakeCase($namespace));
         $prefix = $this->dialog->ask($this->output, $this->dialog->getQuestion('Tablename prefix', $defaultPrefix), $defaultPrefix);
         $prefix = GeneratorUtils::cleanPrefix($prefix);
         if ($this->input->hasOption('prefix')) {
             $this->input->setOption('prefix', $prefix);
         }
     }
     return $prefix;
 }