Author: Fabien Potencier (fabien@symfony.com)
Inheritance: extends Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getQuestionHelper();
     $questionHelper->writeSection($output, 'Welcome to the Symfony2Admingenerator');
     $output->writeln('<comment>Create an admingenerator bundle with generate:bundle</comment>');
     $generator = $input->getOption('generator');
     $question = new ChoiceQuestion('Generator to use (doctrine, doctrine_odm, propel)', array('doctrine', 'doctrine_odm', 'propel'), 0);
     $question->setErrorMessage('Generator to use have to be doctrine, doctrine_odm or propel.');
     $generator = $questionHelper->ask($input, $output, $question);
     $input->setOption('generator', $generator);
     // Model name
     $modelName = $input->getOption('model-name');
     $question = new Question($questionHelper->getQuestion('Model name', $modelName), $modelName);
     $question->setValidator(function ($answer) {
         if (empty($answer) || preg_match('#[^a-zA-Z0-9]#', $answer)) {
             throw new \RuntimeException('Model name should not contain any special characters nor spaces.');
         }
         return $answer;
     });
     $modelName = $questionHelper->ask($input, $output, $question);
     $input->setOption('model-name', $modelName);
     // prefix
     $prefix = $input->getOption('prefix');
     $question = new Question($questionHelper->getQuestion('Prefix of yaml', $prefix), $prefix);
     $question->setValidator(function ($prefix) {
         if (!preg_match('/([a-z]+)/i', $prefix)) {
             throw new \RuntimeException('Prefix have to be a simple word');
         }
         return $prefix;
     });
     $prefix = $questionHelper->ask($input, $output, $question);
     $input->setOption('prefix', $prefix);
     parent::interact($input, $output);
 }
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getDialogHelper();
     $dialog->writeSection($output, 'Welcome to the Symfony2 admin generator');
     $output->writeln('<comment>Create an admingenerator bundle with generate:bundle</comment>');
     $generator = $dialog->askAndValidate($output, $dialog->getQuestion('Generator to use (doctrine, doctrine_odm, propel)', $input->getOption('generator')), function ($generator) {
         if (!in_array($generator, array('doctrine', 'doctrine_odm', 'propel'))) {
             throw new \RuntimeException('Generator to use have to be doctrine, doctrine_odm or propel');
         }
         return $generator;
     }, false, $input->getOption('generator'));
     $input->setOption('generator', $generator);
     // Model name
     $modelName = $dialog->askAndValidate($output, $dialog->getQuestion('Model name', $input->getOption('model-name')), function ($modelName) {
         if (empty($modelName) || preg_match('#[^a-zA-Z0-9]#', $modelName)) {
             throw new \RuntimeException('Model name should not contain any special characters nor spaces.');
         }
         return $modelName;
     }, false, $input->getOption('model-name'));
     $input->setOption('model-name', $modelName);
     // prefix
     $prefix = $dialog->askAndValidate($output, $dialog->getQuestion('Prefix of yaml', $input->getOption('prefix')), function ($prefix) {
         if (!preg_match('/([a-z]+)/i', $prefix)) {
             throw new \RuntimeException('Prefix have to be a simple word');
         }
         return $prefix;
     }, false, $input->getOption('prefix'));
     $input->setOption('prefix', $prefix);
     parent::interact($input, $output);
 }
Ejemplo n.º 3
0
    /**
     * {@inheritdoc}
     */
    public function configure()
    {
        parent::configure();
        $this->setName('victoire:generate:widget')->setDefinition([new InputOption('namespace', '', InputOption::VALUE_REQUIRED, 'The namespace of the widget bundle to create'), new InputOption('dir', '', InputOption::VALUE_REQUIRED, 'The directory where to create the bundle'), new InputOption('bundle-name', '', InputOption::VALUE_REQUIRED, 'The optional bundle name'), new InputOption('orgname', '', InputOption::VALUE_REQUIRED, 'Your organisation name'), new InputOption('widget-name', '', InputOption::VALUE_REQUIRED, 'The widget name'), new InputOption('format', '', InputOption::VALUE_REQUIRED, 'Use the format for configuration files (php, xml, yml, or annotation)'), new InputOption('structure', '', InputOption::VALUE_NONE, 'Whether to generate the whole directory structure'), new InputOption('fields', '', InputOption::VALUE_REQUIRED, 'The fields to create with the new entity'), new InputOption('entity', '', InputOption::VALUE_REQUIRED, 'The entity class name to initialize (shortcut notation)'), new InputOption('parent', '', InputOption::VALUE_REQUIRED, 'The widget this widget will extends'), new InputOption('packagist-parent-name', '', InputOption::VALUE_REQUIRED, 'The packagist name of the widget you want to extends'), new InputOption('content-resolver', '', InputOption::VALUE_NONE, 'Whether to generate a blank ContentResolver to customize widget rendering logic')])->setDescription('Generate a new widget')->setHelp(<<<EOT
The <info>victoire:generate:widget</info> command helps you to generate new widgets.

By default, the command interacts with the developer to tweak the generation.
Any passed option will be used as a default value for the interaction
(<comment>--widget-name</comment> is the only one needed if you follow the
conventions):

<info>php app/console victoire:generate:widget --widget-name=myAwesomeWidget</info>

If you want to disable any user interaction, use <comment>--no-interaction</comment> but don't forget to pass all needed options:

Love you guys, you're awesome xxx
EOT
);
    }
 /**
  * add this bundle skeleton dirs to the beginning of the parent skeletonDirs array.
  *
  * @param BundleInterface $bundle
  *
  * @return string[]
  */
 protected function getSkeletonDirs(BundleInterface $bundle = null)
 {
     $baseSkeletonDirs = parent::getSkeletonDirs($bundle);
     $skeletonDirs = array();
     if (is_dir($dir = $this->getContainer()->get('kernel')->getRootdir() . '/Resources/MultiUserBundleMultiUserBundle/skeleton')) {
         $skeletonDirs[] = $dir;
     }
     $reflClass = new \ReflectionClass($this);
     $dir = dirname($reflClass->getFileName());
     $skeletonDirs[] = $dir . '/../Resources/skeleton';
     $skeletonDirs[] = $dir . '/../Resources';
     return array_merge($skeletonDirs, $baseSkeletonDirs);
 }
Ejemplo n.º 5
0
 /**
  * {@inheritDoc}
  *
  * @param InputInterface  $input  input
  * @param OutputInterface $output output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $output->writeln('Please review Resource/config/config.xml before commiting');
 }