コード例 #1
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('');
     $output->writeln(sprintf('<info>Generation of Crud Rest Controller for "%s" Document in "%s" bundle.</info>', $input->getOption('document'), $input->getOption('bundle')));
     $output->writeln('');
     $document = $input->getOption('document');
     $bundle = $input->getOption('bundle');
     $bundle = Validators::validateBundleName($bundle);
     try {
         $bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
     } catch (\Exception $e) {
         $output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</>', $bundle));
     }
     // Get document metadata
     $dm = $this->getContainer()->get('doctrine_mongodb.odm.document_manager');
     $class_metadata = $dm->getClassMetadata($document);
     $generator = $this->getGenerator($this->getContainer()->get('kernel')->getBundle('RedkingCoreRestBundle'));
     if ($input->getOption('no-controller') === false) {
         $generator->generate($bundle, $class_metadata);
         $output->writeln('Generating the CRUD code: <info>OK</info>');
     }
     if ($input->getOption('no-service') === false) {
         $generator->generateServices($bundle, $class_metadata);
         $output->writeln('Generating the services: <info>OK</info>');
     }
     if ($input->getOption('no-test') === false) {
         $generator->generateTests($bundle, $class_metadata);
         $output->writeln('Generating the functional test: <info>OK</info>');
     }
     if ($input->getOption('no-route') === false) {
         $generator->generateRouting($bundle, $class_metadata);
         $output->writeln('Add routing: <info>OK</info>');
     }
 }
コード例 #2
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getQuestionHelper();
     if ($input->isInteractive() && !$input->getOption('no-summary')) {
         $question = new Question($questionHelper->getQuestion('Do you confirm generation', 'yes', '?'), true);
         if (!$questionHelper->ask($input, $output, $question)) {
             $output->writeln('<error>Command aborted</error>');
             return 1;
         }
     }
     if (null === $input->getOption('controller')) {
         throw new \RuntimeException('The controller option must be provided.');
     }
     list($bundle) = $this->parseShortcutNotation($input->getOption('controller'));
     if (is_string($bundle)) {
         $bundle = Validators::validateBundleName($bundle);
         try {
             $this->getContainer()->get('kernel')->getBundle($bundle);
         } catch (\Exception $e) {
             $output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</>', $bundle));
         }
     }
     /** @var TemplateInterface $generator */
     $generator = $this->getGenerator();
     $questionHelper->writeSection($output, 'Controller generation');
     $errors = array();
     $runner = $questionHelper->getRunner($output, $errors);
     $runner($generator->generate($input->getOption('controller')));
     if (!$input->getOption('no-summary')) {
         $questionHelper->writeGeneratorSummary($output, $generator->getErrors());
     }
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $namespace = $input->getOption('namespace');
     $bundleName = strtr($namespace, array('\\' => ''));
     $bundleName = Validators::validateBundleName($bundleName);
     $bundle = new Bundle($namespace, $bundleName, getcwd() . '/src', 'yml', true);
     /**
      * @var UnitedBundleGenerator $generator
      */
     $generator = $this->getGenerator();
     $output->writeln(sprintf('> Generating a united admin bundle skeleton into <info>%s</info> <comment>OK!</comment>', $this->makePathRelative($bundle->getTargetDirectory())));
     // Write section
     $questionHelper = $this->getQuestionHelper();
     $questionHelper->writeSection($output, 'Bundle generation');
     // generate the bundle
     $generator->generateBundle($bundle);
     // After generation we need to perform some app updates
     $errors = array();
     $runner = $questionHelper->getRunner($output, $errors);
     // register the bundle in the Kernel class
     $runner($this->updateKernel($output, $this->getContainer()->get('kernel'), $bundle));
     // routing importing
     $runner($this->updateRouting($output, $bundle));
     // print summary
     $questionHelper->writeGeneratorSummary($output, $errors);
 }
コード例 #4
0
 /**
  * Executes the command.
  *
  * @param InputInterface $input An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @throws \RuntimeException
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getQuestionHelper();
     if ($input->isInteractive()) {
         $confirmationQuestion = new ConfirmationQuestion($questionHelper->getQuestion('Do you confirm generation', 'yes', '?'), true);
         if (!$questionHelper->ask($input, $output, $confirmationQuestion)) {
             $output->writeln('<error>Command aborted</error>');
             return 1;
         }
     }
     GeneratorUtils::ensureOptionsProvided($input, array('namespace', 'dir'));
     $namespace = Validators::validateBundleNamespace($input->getOption('namespace'));
     if (!($bundle = $input->getOption('bundle-name'))) {
         $bundle = strtr($namespace, array('\\' => ''));
     }
     $bundle = Validators::validateBundleName($bundle);
     $dir = $this::validateTargetDir($input->getOption('dir'), $bundle, $namespace);
     $format = 'yml';
     $questionHelper->writeSection($output, 'Bundle generation');
     if (!$this->getContainer()->get('filesystem')->isAbsolutePath($dir)) {
         $dir = getcwd() . '/' . $dir;
     }
     $generator = $this->getGenerator($this->getApplication()->getKernel()->getBundle("KunstmaanGeneratorBundle"));
     $generator->generate($namespace, $bundle, $dir, $format);
     $output->writeln('Generating the bundle code: <info>OK</info>');
     $errors = array();
     $runner = $questionHelper->getRunner($output, $errors);
     // check that the namespace is already autoloaded
     $runner($this->checkAutoloader($output, $namespace, $bundle));
     // register the bundle in the Kernel class
     $runner($this->updateKernel($questionHelper, $input, $output, $this->getContainer()->get('kernel'), $namespace, $bundle));
     // routing
     $runner($this->updateRouting($questionHelper, $input, $output, $bundle, $format));
     $questionHelper->writeGeneratorSummary($output, $errors);
 }
コード例 #5
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getQuestionHelper();
     if ($input->isInteractive()) {
         $question = new Question($questionHelper->getQuestion('Do you confirm generation', 'yes', '?'), true);
         if (!$questionHelper->ask($input, $output, $question)) {
             $output->writeln('<error>Command aborted</error>');
             return 1;
         }
     }
     if (null === $input->getOption('controller')) {
         throw new \RuntimeException('The controller option must be provided.');
     }
     list($bundle, $controller) = $this->parseShortcutNotation($input->getOption('controller'));
     if (is_string($bundle)) {
         $bundle = Validators::validateBundleName($bundle);
         try {
             $bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
         } catch (\Exception $e) {
             $output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</>', $bundle));
         }
     }
     $questionHelper->writeSection($output, 'Controller generation');
     $generator = $this->getGenerator($bundle);
     $generator->generate($bundle, $controller, $input->getOption('route-format'), $input->getOption('template-format'), $this->parseActions($input->getOption('actions')));
     $output->writeln('Generating the bundle code: <info>OK</info>');
     $questionHelper->writeGeneratorSummary($output, array());
 }
コード例 #6
0
 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     // Start question helper
     $questionHelper = $this->getQuestionHelper();
     $questionHelper->writeSection($output, 'Welcome to the united CRUD generator!');
     // get entity
     $entity = $input->getOption('entity');
     $question = new Question($questionHelper->getQuestion('Entity', $entity), $entity);
     $question->setValidator(function ($answer) {
         return Validators::validateEntityName($answer);
     });
     $complete = new EntitiesAutoCompleter($this->getContainer()->get('doctrine')->getManager());
     $completeEntities = $complete->getSuggestions();
     $question->setAutocompleterValues($completeEntities);
     $entity = $questionHelper->ask($input, $output, $question);
     $input->setOption('entity', $entity);
     // get bundle
     $destinationBundle = $input->getOption('bundle');
     $question = new Question($questionHelper->getQuestion('Destination bundle', $destinationBundle), $destinationBundle);
     $question->setValidator(function ($answer) {
         return Validators::validateBundleName($answer);
     });
     $question->setAutocompleterValues($this->getBundleSuggestions());
     $destinationBundle = $questionHelper->ask($input, $output, $question);
     $input->setOption('bundle', $destinationBundle);
 }
コード例 #7
0
 /**
  * @see Command
  *
  * @throws \InvalidArgumentException When namespace doesn't end with Bundle
  * @throws \RuntimeException         When bundle can't be executed
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getDialogHelper();
     // @codeCoverageIgnoreStart
     if ($input->isInteractive()) {
         if (!$dialog->askConfirmation($output, $dialog->getQuestion('Do you confirm generation', 'yes', '?'), true)) {
             $output->writeln('<error>Command aborted</error>');
             return 1;
         }
     }
     // @codeCoverageIgnoreEnd
     foreach (array('namespace', 'dir') as $option) {
         if (null === $input->getOption($option)) {
             // @codeCoverageIgnoreStart
             throw new \RuntimeException(sprintf('The "%s" option must be provided.', $option));
             // @codeCoverageIgnoreEnd
         }
     }
     $namespace = Validators::validateBundleNamespace($input->getOption('namespace'));
     if (!($bundle = $input->getOption('bundle-name'))) {
         $bundle = strtr($namespace, array('\\' => ''));
     }
     if ($input->getOption('no-strict') == false) {
         $this->checkStrictNamespace($namespace);
     }
     $bundle = Validators::validateBundleName($bundle);
     $dir = Validators::validateTargetDir($input->getOption('dir'), $bundle, $namespace);
     $format = Validators::validateFormat($input->getOption('format'));
     $structure = $input->getOption('structure');
     $dialog->writeSection($output, 'Bundle generation');
     // @codeCoverageIgnoreStart
     if (!$this->getContainer()->get('filesystem')->isAbsolutePath($dir)) {
         $dir = getcwd() . '/' . $dir;
     }
     // @codeCoverageIgnoreEnd
     $generator = $this->getGenerator();
     $generator->generateExt($namespace, $bundle, $dir, $format, $structure, $this->getGeneratorExtraOptions($input));
     $output->writeln('Generating the bundle code: <info>OK</info>');
     $errors = array();
     $runner = $dialog->getRunner($output, $errors);
     // check that the namespace is already autoloaded
     $runner($this->checkAutoloader($output, $namespace, $bundle, $dir));
     // register the bundle in the Kernel class
     if ($this->updateKernel) {
         $runner($this->updateKernel($dialog, $input, $output, $this->getContainer()->get('kernel'), $namespace, $bundle));
     }
     $dialog->writeGeneratorSummary($output, $errors);
 }
コード例 #8
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getQuestionHelper();
     if ($input->isInteractive() && !$input->getOption('no-summary')) {
         $question = new Question($questionHelper->getQuestion('Do you confirm generation', 'yes', '?'), true);
         if (!$questionHelper->ask($input, $output, $question)) {
             $output->writeln('<error>Command aborted</error>');
             return 1;
         }
     }
     if (null === $input->getOption('entity')) {
         throw new \RuntimeException('The entity option must be provided.');
     }
     list($bundle) = $this->parseShortcutNotation($input->getOption('entity'));
     if (is_string($bundle)) {
         $bundle = Validators::validateBundleName($bundle);
         try {
             $this->getContainer()->get('kernel')->getBundle($bundle);
         } catch (\Exception $e) {
             $output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</bg>', $bundle));
         }
     }
     /** @var TemplateInterface $generator */
     $generator = $this->getGenerator();
     if ($input->getOption('no-backend')) {
         $generator->setConfiguration('backend_crud', false);
     }
     if ($input->getOption('actions')) {
         $generator->setConfiguration('actions', explode(',', $input->getOption('actions')));
     }
     $questionHelper->writeSection($output, 'CRUD generation');
     $errors = array();
     $runner = $questionHelper->getRunner($output, $errors);
     if (!$input->getOption('no-backend')) {
         $generator->setConfiguration('backend_bundle', $input->getOption('backend'));
     }
     $runner($generator->generate($input->getOption('entity'), $output));
     if (!$input->getOption('no-backend')) {
         $questionHelper->writeSection($output, "Don't forget to run sylius:rbac:initialize command");
     }
     if (!$input->getOption('no-summary')) {
         $questionHelper->writeGeneratorSummary($output, $generator->getErrors());
     }
 }
コード例 #9
0
 /**
  * @see Command
  *
  * @throws \InvalidArgumentException When namespace doesn't end with Bundle
  * @throws \RuntimeException         When bundle can't be executed
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getQuestionHelper();
     $question = new ConfirmationQuestion('Do you confirm generation?', true);
     if ($input->isInteractive()) {
         if (!$helper->ask($input, $output, $question)) {
             $output->writeln('<error>Command aborted</error>');
             return 1;
         }
     }
     foreach (array('namespace', 'short-name') as $option) {
         if (null === $input->getOption($option)) {
             throw new \RuntimeException(sprintf('The "%s" option must be provided.', $option));
         }
     }
     $namespace = Validators::validateBundleNamespace($input->getOption('namespace'));
     $bundle = strtr($namespace, array('\\' => ''));
     $bundle = Validators::validateBundleName($bundle);
     $dir = realpath(__DIR__ . '/../../../../../../');
     if (null !== $input->getOption('dir')) {
         $dir = $input->getOption('dir');
     }
     $dir = Validators::validateTargetDir($dir, $bundle, $namespace);
     if (!$this->getContainer()->get('filesystem')->isAbsolutePath($dir)) {
         $dir = getcwd() . '/' . $dir;
     }
     $format = 'yml';
     $format = Validators::validateFormat($format);
     $helper->writeSection($output, 'Bundle generation');
     /** @var ComponentGenerator $generator */
     $generator = $this->getGenerator();
     $generator->generate($namespace, $bundle, $dir, $format);
     $output->writeln('Generating the bundle code: <info>OK</info>');
     $errors = array();
     $runner = $helper->getRunner($output, $errors);
     //update parameters.yml file in vendor
     $shortName = $input->getOption('short-name');
     $runner($this->updateParameters($output, $shortName, $dir, $namespace, $bundle));
     $helper->writeGeneratorSummary($output, $errors);
 }
 /**
  * @see Command
  *
  * @throws \InvalidArgumentException When namespace doesn't end with Bundle
  * @throws \RuntimeException         When bundle can't be executed
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getDialogHelper();
     if ($input->isInteractive()) {
         if (!$dialog->askConfirmation($output, $dialog->getQuestion('Do you confirm generation', 'yes', '?'), true)) {
             $output->writeln('<error>Command aborted</error>');
             return 1;
         }
     }
     foreach (array('namespace', 'dir') as $option) {
         if (null === $input->getOption($option)) {
             throw new \RuntimeException(sprintf('The "%s" option must be provided.', $option));
         }
     }
     $namespace = Validators::validateBundleNamespace($input->getOption('namespace'));
     if (!($bundle = $input->getOption('bundle-name'))) {
         $bundle = strtr($namespace, array('\\' => ''));
     }
     $bundle = Validators::validateBundleName($bundle);
     $format = Validators::validateFormat($input->getOption('format'));
     $dir = $input->getOption('dir') . '/';
     $structure = $input->getOption('structure');
     $dialog->writeSection($output, 'Bundle generation');
     if (!$this->getContainer()->get('filesystem')->isAbsolutePath($dir)) {
         $dir = getcwd() . '/' . $dir;
     }
     $generator = $this->getGenerator();
     $generator->setGenerator($input->getOption('generator'));
     $generator->setPrefix($input->getOption('prefix'));
     $generator->generate($namespace, $bundle, $dir, $format, $structure);
     $output->writeln('Generating the bundle code: <info>OK</info>');
     $errors = array();
     $runner = $dialog->getRunner($output, $errors);
     // routing
     $runner($this->updateRouting($dialog, $input, $output, $bundle, $format));
     $dialog->writeGeneratorSummary($output, $errors);
 }
コード例 #11
0
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getQuestionHelper();
     $questionHelper->writeSection($output, 'Welcome to the Symfony2 bundle generator');
     // namespace
     $namespace = null;
     try {
         // validate the namespace option (if any) but don't require the vendor namespace
         $namespace = $input->getOption('namespace') ? Validators::validateBundleNamespace($input->getOption('namespace'), false) : null;
     } catch (\Exception $error) {
         $output->writeln($questionHelper->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
     }
     if (null === $namespace) {
         $output->writeln(array('', 'Your application code must be written in <comment>bundles</comment>. This command helps', 'you generate them easily.', '', 'Each bundle is hosted under a namespace (like <comment>Acme/Bundle/BlogBundle</comment>).', 'The namespace should begin with a "vendor" name like your company name, your', 'project name, or your client name, followed by one or more optional category', 'sub-namespaces, and it should end with the bundle name itself', '(which must have <comment>Bundle</comment> as a suffix).', '', 'See http://symfony.com/doc/current/cookbook/bundles/best_practices.html#index-1 for more', 'details on bundle naming conventions.', '', 'Use <comment>/</comment> instead of <comment>\\ </comment> for the namespace delimiter to avoid any problem.', ''));
         $acceptedNamespace = false;
         while (!$acceptedNamespace) {
             $question = new Question($questionHelper->getQuestion('Bundle namespace', $input->getOption('namespace')), $input->getOption('namespace'));
             $question->setValidator(function ($answer) {
                 return Validators::validateBundleNamespace($answer, false);
             });
             $namespace = $questionHelper->ask($input, $output, $question);
             // mark as accepted, unless they want to try again below
             $acceptedNamespace = true;
             // see if there is a vendor namespace. If not, this could be accidental
             if (false === strpos($namespace, '\\')) {
                 // language is (almost) duplicated in Validators
                 $msg = array();
                 $msg[] = '';
                 $msg[] = sprintf('The namespace sometimes contain a vendor namespace (e.g. <info>VendorName/BlogBundle</info> instead of simply <info>%s</info>).', $namespace, $namespace);
                 $msg[] = 'If you\'ve *did* type a vendor namespace, try using a forward slash <info>/</info> (<info>Acme/BlogBundle</info>)?';
                 $msg[] = '';
                 $output->writeln($msg);
                 $question = new ConfirmationQuestion($questionHelper->getQuestion(sprintf('Keep <comment>%s</comment> as the bundle namespace (choose no to try again)?', $namespace), 'yes'), true);
                 $acceptedNamespace = $questionHelper->ask($input, $output, $question);
             }
         }
         $input->setOption('namespace', $namespace);
     }
     // bundle name
     $bundle = null;
     try {
         $bundle = $input->getOption('bundle-name') ? Validators::validateBundleName($input->getOption('bundle-name')) : null;
     } catch (\Exception $error) {
         $output->writeln($questionHelper->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
     }
     if (null === $bundle) {
         $bundle = strtr($namespace, array('\\Bundle\\' => '', '\\' => ''));
         $output->writeln(array('', 'In your code, a bundle is often referenced by its name. It can be the', 'concatenation of all namespace parts but it\'s really up to you to come', 'up with a unique name (a good practice is to start with the vendor name).', 'Based on the namespace, we suggest <comment>' . $bundle . '</comment>.', ''));
         $question = new Question($questionHelper->getQuestion('Bundle name', $bundle), $bundle);
         $question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateBundleName'));
         $bundle = $questionHelper->ask($input, $output, $question);
         $input->setOption('bundle-name', $bundle);
     }
     // target dir
     $dir = null;
     try {
         $dir = $input->getOption('dir') ? Validators::validateTargetDir($input->getOption('dir'), $bundle, $namespace) : null;
     } catch (\Exception $error) {
         $output->writeln($questionHelper->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
     }
     if (null === $dir) {
         $dir = dirname($this->getContainer()->getParameter('kernel.root_dir')) . '/src';
         $output->writeln(array('', 'The bundle can be generated anywhere. The suggested default directory uses', 'the standard conventions.', ''));
         $question = new Question($questionHelper->getQuestion('Target directory', $dir), $dir);
         $question->setValidator(function ($dir) use($bundle, $namespace) {
             return Validators::validateTargetDir($dir, $bundle, $namespace);
         });
         $dir = $questionHelper->ask($input, $output, $question);
         $input->setOption('dir', $dir);
     }
     // format
     $format = null;
     try {
         $format = $input->getOption('format') ? Validators::validateFormat($input->getOption('format')) : null;
     } catch (\Exception $error) {
         $output->writeln($questionHelper->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
     }
     if (null === $format) {
         $output->writeln(array('', 'Determine the format to use for the generated configuration.', ''));
         $question = new Question($questionHelper->getQuestion('Configuration format (yml, xml, php, or annotation)', $input->getOption('format')), $input->getOption('format'));
         $question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateFormat'));
         $format = $questionHelper->ask($input, $output, $question);
         $input->setOption('format', $format);
     }
     // optional files to generate
     $output->writeln(array('', 'To help you get started faster, the command can generate some', 'code snippets for you.', ''));
     $structure = $input->getOption('structure');
     $question = new ConfirmationQuestion($questionHelper->getQuestion('Do you want to generate the whole directory structure', 'no', '?'), false);
     if (!$structure && $questionHelper->ask($input, $output, $question)) {
         $structure = true;
     }
     $input->setOption('structure', $structure);
     // summary
     $output->writeln(array('', $this->getHelper('formatter')->formatBlock('Summary before generation', 'bg=blue;fg=white', true), '', sprintf("You are going to generate a \"<info>%s\\%s</info>\" bundle\nin \"<info>%s</info>\" using the \"<info>%s</info>\" format.", $namespace, $bundle, $dir, $format), ''));
 }
コード例 #12
0
 /**
  * Gets type based on input params.
  *
  * @return array('bundleName','entityName')
  */
 protected function getGenerationParams()
 {
     if ($this->input->getOption('entity')) {
         $this->type = 'entity';
         $this->output->writeln(array('You choose <info>entity</info> option for generation.', 'Each <info>entity</info> is hosted under a namespace (like <comment>AcmeBlogBundle:Article</comment>).'));
         $entityName = null;
         $entityName = $this->questionHelper->ask($this->input, $this->output, $this->questionHelper->getQuestion('Please, set  <comment>entity namespace</comment>', $entityName));
         $entityName = Validators::validateEntityName($entityName);
         $entityNameArray = explode(':', $entityName);
         $bundleName = $entityNameArray[0];
     } else {
         if ($this->input->getOption('project')) {
             $this->type = 'project';
             $this->output->writeln('You choose <info>project</info> option for generation.');
         } else {
             $this->type = "bundle";
             if ($this->input->isInteractive()) {
                 $this->output->writeln(array('You choose <info>bundle</info> option for generation.', 'Each bundle is hosted under a namespace (like <comment>Acme/Bundle/BlogBundle</comment>).', 'Please write namespace of your bundle to generate fixture data.'));
                 $namespace = null;
                 //DialogHelper has not support anymore
                 $question = new Question($this->questionHelper->getQuestion('Please, set  <comment>bundle namespace</comment>', $namespace), $namespace);
                 $namespace = $this->questionHelper->ask($this->input, $this->output, $question);
                 $namespace = Validators::validateBundleNamespace($namespace);
                 $bundleName = strtr($namespace, array('\\' => ''));
             }
         }
     }
     $overrideFiles = null;
     //changed askconfirmation()  into doAsk()
     $questionFiles = new Question($this->questionHelper->getQuestion('Override existing backup files', $namespace), $namespace);
     $overrideFiles = $this->questionHelper->doAsk($this->output, $questionFiles, true);
     return array('bundleName' => !empty($bundleName) ? Validators::validateBundleName($bundleName) : null, 'entityName' => !empty($entityName) ? $entityName : null, 'overrideFiles' => !empty($overrideFiles) ? $overrideFiles : null);
 }
コード例 #13
0
 /**
  * @see Command
  *
  * @throws \InvalidArgumentException When namespace doesn't end with Bundle
  * @throws \RuntimeException         When bundle can't be executed
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getQuestionHelper();
     if ($input->isInteractive()) {
         $question = new ConfirmationQuestion('Do you confirm generation?', true);
         if (!$questionHelper->ask($input, $output, $question)) {
             $output->writeln('<error>Command aborted</error>');
             return 1;
         }
     }
     foreach (array('namespace', 'dir') as $option) {
         if (null === $input->getOption($option)) {
             throw new \RuntimeException(sprintf('The "%s" option must be provided.', $option));
         }
     }
     $namespace = Validators::validateBundleNamespace($input->getOption('namespace'));
     if (!($bundle = $input->getOption('bundle-name'))) {
         $bundle = strtr($namespace, array('\\' => ''));
     }
     $bundle = Validators::validateBundleName($bundle);
     $dir = Validators::validateTargetDir($input->getOption('dir'), $bundle, $namespace);
     $format = Validators::validateFormat($input->getOption('format'));
     $structure = $input->getOption('structure');
     $questionHelper->writeSection($output, 'Bundle generation');
     if (!$this->getContainer()->get('filesystem')->isAbsolutePath($dir)) {
         $dir = getcwd() . '/' . $dir;
     }
     $generatorName = $input->getOption('generator');
     $modelName = $input->getOption('model-name');
     $generator = $this->createGenerator();
     $generator->setGenerator($generatorName);
     $generator->setPrefix($input->getOption('prefix'));
     $generator->generate($namespace, $bundle, $dir, $format, $structure, $generatorName, $modelName);
     $output->writeln('Generating the bundle code: <info>OK</info>');
     $errors = array();
     $runner = $questionHelper->getRunner($output, $errors);
     // check that the namespace is already autoloaded
     $runner($this->checkAutoloader($output, $namespace, $bundle, $dir));
     // register the bundle in the Kernel class
     $runner($this->updateKernel($questionHelper, $input, $output, $this->getContainer()->get('kernel'), $namespace, $bundle));
     // routing
     $runner($this->updateRouting($questionHelper, $input, $output, $bundle, $format));
     $questionHelper->writeGeneratorSummary($output, $errors);
 }
コード例 #14
0
 /**
  * Creates the Bundle object based on the user's (non-interactive) input.
  *
  * @param InputInterface $input
  *
  * @return Bundle
  */
 protected function createBundleObject(InputInterface $input)
 {
     foreach (array('namespace', 'dir') as $option) {
         if (null === $input->getOption($option)) {
             throw new \RuntimeException(sprintf('The "%s" option must be provided.', $option));
         }
     }
     $shared = $input->getOption('shared');
     $namespace = Validators::validateBundleNamespace($input->getOption('namespace'), $shared);
     if (!($bundleName = $input->getOption('bundle-name'))) {
         $bundleName = strtr($namespace, array('\\' => ''));
     }
     $bundleName = Validators::validateBundleName($bundleName);
     $dir = $input->getOption('dir');
     if (null === $input->getOption('format')) {
         $input->setOption('format', 'annotation');
     }
     $format = Validators::validateFormat($input->getOption('format'));
     // an assumption that the kernel root dir is in a directory (like app/)
     $projectRootDirectory = $this->getContainer()->getParameter('kernel.root_dir') . '/..';
     if (!$this->getContainer()->get('filesystem')->isAbsolutePath($dir)) {
         $dir = $projectRootDirectory . '/' . $dir;
     }
     // add trailing / if necessary
     $dir = '/' === substr($dir, -1, 1) ? $dir : $dir . '/';
     $bundle = new Bundle($namespace, $bundleName, $dir, $format, $shared);
     // not shared - put the tests in the root
     if (!$shared) {
         $testsDir = $projectRootDirectory . '/tests/' . $bundleName;
         $bundle->setTestsDirectory($testsDir);
     }
     return $bundle;
 }
コード例 #15
0
 /**
  * Validate bundle
  *
  * @param $bundle
  *
  * @return AbstractResourceBundle
  */
 private function validateBundle($bundle)
 {
     Validators::validateBundleName($bundle);
     try {
         $bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
     } catch (\Exception $e) {
         throw new \RuntimeException('Cannot patch "%s", bundle not found.', $bundle);
     }
     if (!$bundle instanceof AbstractResourceBundle) {
         throw new \RuntimeException('You need to implement AbstractResourceBundle for "%s"', $bundle->getName());
     }
     return $bundle;
 }
コード例 #16
0
 protected function createGenerator()
 {
     $generator = new RestControllerGenerator($this->getContainer()->get('filesystem'));
     list($bundle, $entity) = $this->parseShortcutNotation($this->input->getOption('entity'));
     $generator->setEntityName($entity);
     if (is_string($bundle)) {
         $bundle = Validators::validateBundleName($bundle);
         try {
             $bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
         } catch (\Exception $e) {
             $this->output->writeln(sprintf('<bg=red>Bundle "%s" does not exists.</>', $bundle));
         }
     }
     /** @todo Check entity is a valid entity */
     if ($this->input->getOption("mongo")) {
         $generator->setMongo(true);
     }
     /** @todo Check entity is a valid entity */
     if ($this->input->getOption("phpcr")) {
         $generator->setPhpcr(true);
     }
     $generator->setEntityBundle($bundle);
     return $generator;
 }
コード例 #17
0
 /**
  * Creates the Bundle object based on the user's (non-interactive) input.
  *
  * @param InputInterface $input
  *
  * @return Bundle
  */
 protected function createBundleObject(InputInterface $input)
 {
     foreach (array('namespace', 'dir') as $option) {
         if (null === $input->getOption($option)) {
             throw new \RuntimeException(sprintf('The "%s" option must be provided.', $option));
         }
     }
     $shared = $input->getOption('shared');
     $namespace = Validators::validateBundleNamespace($input->getOption('namespace'), $shared);
     if (!($bundleName = $input->getOption('bundle-name'))) {
         $bundleName = strtr($namespace, array('\\' => ''));
     }
     $bundleName = Validators::validateBundleName($bundleName);
     $dir = $input->getOption('dir');
     if (null === $input->getOption('format')) {
         $input->setOption('format', 'annotation');
     }
     $format = Validators::validateFormat($input->getOption('format'));
     if (!$this->getContainer()->get('filesystem')->isAbsolutePath($dir)) {
         $dir = getcwd() . '/' . $dir;
     }
     // add trailing / if necessary
     $dir = '/' === substr($dir, -1, 1) ? $dir : $dir . '/';
     return new Bundle($namespace, $bundleName, $dir, $format, $shared);
 }
コード例 #18
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('name');
     try {
         $useCase = self::USE_CASE_BUNDLE;
         $bundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('name'));
     } catch (\InvalidArgumentException $e) {
         $useCase = self::USE_CASE_CONTROLLER;
     }
     if ($useCase === self::USE_CASE_CONTROLLER) {
         list($bundle, $name) = $this->parseShortcutNotation($input->getArgument('name'));
         $output->writeln(sprintf('Generating security for controller "<info>%s</info>"', $bundle . ":" . $name));
         if (is_string($bundle)) {
             $bundle = Validators::validateBundleName($bundle);
             try {
                 $bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
             } catch (\Exception $e) {
                 $output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</>', $bundle));
             }
         }
         $bundleDirectory = $bundle->getPath();
         $controllerPath = $this->getControllerPath($bundleDirectory, $name);
         $copyControllerPath = $this->getCopyControllerPath($bundleDirectory, $name);
         if (file_exists($controllerPath) === false) {
             throw new \RuntimeException(sprintf('Controller "%s" does not exists', $name));
         }
         if (file_exists($copyControllerPath) === true) {
             throw new \RuntimeException(sprintf('Copy of controller "%s" exist. Remove this from the backup.', $name));
         }
         $creator = new PermissionCreator($controllerPath);
         $buckupDirectory = $this->createBackupDirectory($bundleDirectory);
         $this->createCopy($controllerPath, $copyControllerPath);
         @($annotatedSource = $creator->annotate());
         $result = file_put_contents($controllerPath, $annotatedSource);
         if ($result === false) {
             $this->throwIOException();
         }
         $output->writeln("Files were modified");
         return 0;
     } else {
         $output->writeln(sprintf('Generating security for bundle "<info>%s</info>"', $bundle->getName()));
         $bundleDirectory = $bundle->getPath();
         if ($this->backupExists($bundleDirectory) == true) {
             throw new \RuntimeException(sprintf('Backup exists!'));
         }
         $buckupDirectory = $this->createBackupDirectory($bundleDirectory);
         $controllerDirectory = $this->getControllerDirectory($bundleDirectory);
         foreach (new \DirectoryIterator($controllerDirectory) as $item) {
             $fileInfo = $item->getFileInfo();
             if ($fileInfo->isFile() == true) {
                 $copyControllerPath = $buckupDirectory . DIRECTORY_SEPARATOR . $fileInfo->getFilename();
                 $this->createCopy($fileInfo->getRealPath(), $copyControllerPath);
                 $creator = new PermissionCreator($fileInfo->getRealPath());
                 @($annotatedSource = $creator->annotate());
                 $result = file_put_contents($fileInfo->getRealPath(), $annotatedSource);
                 if ($result === false) {
                     $this->throwIOException();
                 }
             }
         }
         $output->writeln("Files were modified");
         return 0;
     }
 }
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getQuestionHelper();
     $questionHelper->writeSection($output, 'Welcome to the eZ FieldType generator');
     // target bundle
     $targetBundle = null;
     try {
         // validate the namespace option (if any) but don't require the vendor namespace
         $targetBundle = $input->getOption('target-bundle') ? Validators::validateBundleName($input->getOption('target-bundle'), false) : null;
     } catch (\Exception $error) {
         $output->writeln($questionHelper->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
     }
     if ($targetBundle === null) {
         $output->writeln(array('', 'Your FieldType must be created in a <comment>bundle</comment>. ', '', 'If you don\'t have a bundle for it, please create one using <comment>generate:bundle</comment> first'));
         $acceptedTargetBundle = false;
         while (!$acceptedTargetBundle) {
             $question = new Question($questionHelper->getQuestion('Target bundle name', $input->getOption('target-bundle')), $input->getOption('target-bundle'));
             $question->setValidator(function ($answer) {
                 return Validators::validateBundleName($answer);
             });
             $targetBundle = $questionHelper->ask($input, $output, $question);
             // mark as accepted, unless they want to try again below
             $acceptedTargetBundle = true;
         }
         $input->setOption('target-bundle', $targetBundle);
     }
     $input->setOption('target-bundle-dir', $this->getContainer()->get('kernel')->locateResource("@" . $input->getOption('target-bundle')));
     // FieldType name
     $fieldTypeName = null;
     try {
         // @todo validate me
         $fieldTypeName = $input->getOption('fieldtype-name');
     } catch (\Exception $error) {
     }
     if (null === $fieldTypeName) {
         $output->writeln(array('', 'A FieldType requires a unique identifier.', 'Identifiers can contain alphanumeric characters as well as underscores', ''));
         $question = new Question($questionHelper->getQuestion('FieldType name', $fieldTypeName), $fieldTypeName);
         // @todo validate me // $question->setValidator();
         $fieldTypeName = $questionHelper->ask($input, $output, $question);
         $fieldTypeRegistry = $this->getContainer()->get('ezpublish.persistence.field_type_registry');
         $fieldTypeExists = true;
         try {
             $fieldTypeRegistry->getFieldType($fieldTypeName);
         } catch (\Exception $e) {
             $fieldTypeExists = false;
         }
         if ($fieldTypeExists === true) {
             throw new InvalidArgumentException("A fieldtype {$fieldTypeName} already exists");
         }
         $input->setOption('fieldtype-name', $fieldTypeName);
     }
     // summary
     $output->writeln(array('', $this->getHelper('formatter')->formatBlock('Summary before generation', 'bg=blue;fg=white', true), '', sprintf("You are going to generate a \"<info>%s</info>\" FieldType in the \"<info>%s</info>\" bundle.", $fieldTypeName, $targetBundle), ''));
 }
コード例 #20
0
 /**
  * Take arguments and options defined in $this->interact() and generate a new Widget.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @see Command
  *
  * @throws \InvalidArgumentException When namespace doesn't end with Bundle
  * @throws \RuntimeException         When bundle can't be executed
  *
  * @return int|null
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getQuestionHelper();
     if ($input->isInteractive()) {
         $question = new ConfirmationQuestion($questionHelper->getQuestion('Do you confirm generation', 'yes', '?'), true);
         if (!$questionHelper->ask($input, $output, $question)) {
             $output->writeln('<error>Command aborted</error>');
             return 1;
         }
     }
     foreach (['namespace', 'dir'] as $option) {
         if (null === $input->getOption($option)) {
             throw new \RuntimeException(sprintf('The "%s" option must be provided.', $option));
         }
     }
     $namespace = Validators::validateBundleNamespace($input->getOption('namespace'));
     if (!($bundle = $input->getOption('bundle-name'))) {
         $bundle = strtr($namespace, ['\\' => '']);
     }
     $orgname = $input->getOption('orgname');
     if (null === $input->getOption('orgname')) {
         $orgname = $input->setOption('orgname', 'friendsofvictoire');
     }
     $parent = $input->getOption('parent');
     if (null === $input->getOption('parent')) {
         $parent = $input->setOption('parent', null);
     }
     $packagistParentName = $input->getOption('packagist-parent-name');
     if (null === $input->getOption('packagist-parent-name')) {
         $packagistParentName = $input->setOption('packagist-parent-name', null);
     }
     $bundle = Validators::validateBundleName($bundle);
     $dir = Validators::validateTargetDir($input->getOption('dir'), $bundle, $namespace);
     if (null === $input->getOption('format')) {
         $input->setOption('format', 'annotation');
     }
     $format = Validators::validateFormat($input->getOption('format'));
     $structure = $input->getOption('structure');
     $contentResolver = $input->getOption('content-resolver');
     $questionHelper->writeSection($output, 'Bundle generation');
     if (!$this->getContainer()->get('filesystem')->isAbsolutePath($dir)) {
         $dir = getcwd() . '/' . $dir;
     }
     $fields = $this->parseFields($input->getOption('fields'));
     $parentContentResolver = $this->getContainer()->has('victoire_core.widget_' . strtolower($parent) . '_content_resolver');
     $generator = $this->getGenerator();
     $generator->generate($namespace, $bundle, $dir, $format, $structure, $fields, $parent, $packagistParentName, $contentResolver, $parentContentResolver, $orgname);
     $output->writeln('Generating the bundle code: <info>OK</info>');
     $errors = [];
     $runner = $questionHelper->getRunner($output, $errors);
     // check that the namespace is already autoloaded
     $runner($this->checkAutoloader($output, $namespace, $bundle, $dir));
     // register the bundle in the Kernel class
     $runner($this->updateKernel($questionHelper, $input, $output, $this->getContainer()->get('kernel'), $namespace, $bundle));
     $questionHelper->writeGeneratorSummary($output, $errors);
 }
コード例 #21
0
 /**
  * @see Command
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     $questionHelper = $this->getQuestionHelper();
     $questionHelper->writeSection($output, 'Welcome to the Sylius resource generator');
     // namespace
     $output->writeln(array('', 'This command helps you generate Sylius resource.', '', 'First, you need to give the entity name you want to generate.', 'You must use the shortcut notation like <comment>AcmeBlogBundle:Post</comment>.', ''));
     $bundleNames = $this->getContainer()->get('kernel')->getBundles();
     $bundleList = array();
     foreach ($bundleNames as $bundle) {
         if ($bundle instanceof AbstractResourceBundle) {
             $bundleList[] = $bundle->getName();
         }
     }
     while (true) {
         $question = new Question($questionHelper->getQuestion('The Entity shortcut name', $input->getOption('resource')), $input->getOption('resource'));
         $question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateEntityName'));
         $question->setAutocompleterValues($bundleList);
         $resource = $questionHelper->ask($input, $output, $question);
         $resource = Validators::validateEntityName($resource);
         list($bundle, $entity) = $this->parseShortcutNotation($resource);
         $bundle = Validators::validateBundleName($bundle);
         try {
             $this->getContainer()->get('kernel')->getBundle($bundle);
         } catch (\Exception $e) {
             $output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</>', $bundle));
             continue;
         }
         if (in_array($entity, Validators::getReservedWords())) {
             $output->writeln(sprintf('<bg=red> "%s" is a reserved word</>.', $entity));
             continue;
         }
         break;
     }
     $input->setOption('resource', $resource);
     $dialog = $this->getHelper('dialog');
     if ($dialog->askConfirmation($output, '<question>Would you add form? (y/N)</question>')) {
         $this->commands[] = array('avoo:generate:form', '--entity' => $resource, '--no-summary' => true);
         if ($dialog->askConfirmation($output, '<question>Would you add controller? (y/N)</question>')) {
             $this->commands[] = array('avoo:generate:controller', '--controller' => $resource, '--no-summary' => true);
             if ($dialog->askConfirmation($output, '<question>Would you add CRUD? (y/N)</question>')) {
                 $backend = $dialog->askConfirmation($output, '<question>With backend? (y/N)</question>');
                 $crud = array();
                 if (!$backend) {
                     $crud['--no-backend'] = true;
                 } else {
                     while (true) {
                         $question = new Question($questionHelper->getQuestion('Backend bundle', null));
                         $question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateBundleName'));
                         $question->setAutocompleterValues($bundleList);
                         $backendBundle = $questionHelper->ask($input, $output, $question);
                         try {
                             $this->getContainer()->get('kernel')->getBundle($backendBundle);
                             break;
                         } catch (\Exception $e) {
                             $output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</>', $backendBundle));
                             $input->setOption('no-summary', null);
                             continue;
                         }
                     }
                     $crud['--backend'] = $backendBundle;
                 }
                 $this->commands[] = array_merge(array('avoo:generate:crud', '--entity' => $resource, '--no-summary' => true), $crud);
             }
         }
         $this->commands[] = array('cache:clear', '--no-warmup' => true);
     }
 }