/** * @see Command */ 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; } } $entity = Validators::validateEntityName($input->getOption('entity')); list($bundle, $entity) = $this->parseShortcutNotation($entity); $prefix = $this->getRoutePrefix($input, $entity); $forceOverwrite = $input->getOption('overwrite'); $questionHelper->writeSection($output, 'REST api generation'); $entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle) . '\\' . $entity; $metadata = $this->getEntityMetadata($entityClass); $bundle = $this->getContainer()->get('kernel')->getBundle($bundle); $resource = $input->getOption('resource'); $document = $input->getOption('document'); $generator = $this->getGenerator($bundle); $generator->generate($bundle, $entity, $metadata[0], $prefix, $forceOverwrite, $resource, $document); $output->writeln('Generating the REST api code: <info>OK</info>'); $errors = array(); // form $this->generateForm($bundle, $entity, $metadata); $output->writeln('Generating the Form code: <info>OK</info>'); $questionHelper->writeGeneratorSummary($output, $errors); }
/** * {@inheritdoc} */ 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('entity', 'fields', 'prefix')); $entityInput = Validators::validateEntityName($input->getOption('entity')); list($bundleName, $entity) = $this->parseShortcutNotation($entityInput); $format = 'annotation'; $fields = $this->parseFields($input->getOption('fields')); $prefix = $input->getOption('prefix'); $questionHelper->writeSection($output, 'Entity generation'); $bundle = $this->getContainer()->get('kernel')->getBundle($bundleName); $generator = $this->getGenerator($this->getApplication()->getKernel()->getBundle("KunstmaanGeneratorBundle")); $generator->generate($bundle, $entity, $format, array_values($fields), $input->getOption('with-repository'), $prefix); $output->writeln('Generating the entity code: <info>OK</info>'); $withAdminlist = $input->getOption('with-adminlist'); if ($withAdminlist) { $command = $this->getApplication()->find('kuma:generate:adminlist'); $arguments = array('command' => 'doctrine:fixtures:load', '--entity' => $entityInput); $input = new ArrayInput($arguments); $command->run($input, $output); } $questionHelper->writeGeneratorSummary($output, array()); $output->writeln(array('Make sure you update your database first before you test the entity/adminlist:', ' Directly update your database: <comment>app/console doctrine:schema:update --force</comment>', ' Create a Doctrine migration and run it: <comment>app/console doctrine:migrations:diff && app/console doctrine:migrations:migrate</comment>', '')); }
/** * @see Command */ 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; } } $entity = Validators::validateEntityName($input->getOption('entity')); list($bundle, $entity) = $this->parseShortcutNotation($entity); $format = Validators::validateFormat($input->getOption('format')); $prefix = $this->getRoutePrefix($input, $entity); $withWrite = $input->getOption('with-write'); $dialog->writeSection($output, 'CRUD generation'); $entityClass = $this->getContainer()->get('doctrine')->getEntityNamespace($bundle) . '\\' . $entity; $metadata = $this->getEntityMetadata($entityClass); $bundle = $this->getContainer()->get('kernel')->getBundle($bundle); $generator = $this->getGenerator(); $generator->generate($bundle, $entity, $metadata[0], $format, $prefix, $withWrite); $output->writeln('Generating the CRUD code: <info>OK</info>'); $errors = array(); $runner = $dialog->getRunner($output, $errors); // form if ($withWrite) { $this->generateForm($bundle, $entity, $metadata); $output->writeln('Generating the Form code: <info>OK</info>'); } // routing if ('annotation' != $format) { $runner($this->updateRouting($dialog, $input, $output, $bundle, $format, $entity, $prefix)); } $dialog->writeGeneratorSummary($output, $errors); }
/** * @throws \InvalidArgumentException When the bundle doesn't end with Bundle (Example: "Bundle/MySampleBundle") */ 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; } } $entity = Validators::validateEntityName($input->getOption('entity')); $translationEntity = Validators::validateEntityName(sprintf('%sTranslation', $input->getOption('entity'))); list($bundle, $entity) = $this->parseShortcutNotation($entity); list($translationBundle, $translationEntity) = $this->parseShortcutNotation($translationEntity); $format = Validators::validateFormat($input->getOption('format')); $fields = $this->parseFields($input->getOption('fields')); $translatableFields = $this->parseFields($input->getOption('translatable-fields')); $dialog->writeSection($output, 'Entities generation'); $kernel = $this->getContainer()->get('kernel'); $bundle = $kernel->getBundle($bundle); $translationBundle = $kernel->getBundle($translationBundle); /** @var OrkestroEntityGenerator $generator */ $generator = $this->getGenerator(); $generator->generateTranslatable($bundle, $entity, $translationEntity, $format, array_values($fields), array_values($translatableFields), $input->getOption('with-repository')); $output->writeln('Generating the entities code: <info>OK</info>'); $dialog->writeGeneratorSummary($output, array()); }
/** * @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>'); } }
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()); } }
/** * 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); }
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()); }
/** * {@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); }
/** * @throws \InvalidArgumentException When the bundle doesn't end with Bundle (Example: "Bundle/MySampleBundle") */ 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; } } $entity = Validators::validateEntityName($input->getOption('entity')); $fields = $this->parseFields($input->getOption('fields')); if (!$input->getOption('no-summary')) { $questionHelper->writeSection($output, 'Entity generation'); } /** @var TemplateInterface $generator */ $generator = $this->getGenerator(); $generator->setConfiguration('fields', $fields); if ($input->getOption('no-interface')) { $generator->setConfiguration('with_interface', false); } $errors = array(); $runner = $questionHelper->getRunner($output, $errors); $runner($generator->generate($entity)); if (!$input->getOption('no-summary')) { $questionHelper->writeGeneratorSummary($output, $generator->getErrors()); } }
/** * Asks for the namespace and sets it on the InputInterface as the 'namespace' option, if this option is not set yet. * * @param array $text What you want printed before the namespace is asked. * * @return string The namespace. But it's also been set on the InputInterface. */ public function askForNamespace(array $text = null) { $namespace = $this->input->hasOption('namespace') ? $this->input->getOption('namespace') : null; // When the Namespace is filled in return it immediately if valid. try { if (!is_null($namespace) && !empty($namespace)) { Validators::validateBundleNamespace($namespace); return $namespace; } } catch (\Exception $error) { $this->writeError(array("Namespace '{$namespace}' is incorrect. Please provide a correct value.", $error->getMessage())); exit; } $ownBundles = $this->getOwnBundles(); if (count($ownBundles) <= 0) { $this->writeError("Looks like you don't have created a bundle for your project, create one first.", true); } $namespace = ''; // If we only have 1 or more bundles, we can prefill it. if (count($ownBundles) > 0) { $namespace = $ownBundles[1]['namespace'] . '/' . $ownBundles[1]['name']; } $namespaces = $this->getNamespaceAutoComplete($this->kernel); if (!is_null($text) && count($text) > 0) { $this->output->writeln($text); } $question = new Question($this->questionHelper->getQuestion('Bundle Namespace', $namespace), $namespace); $question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateBundleNamespace')); $question->setAutocompleterValues($namespaces); $namespace = $this->questionHelper->ask($this->input, $this->output, $question); if ($this->input->hasOption('namespace')) { $this->input->setOption('namespace', $namespace); } return $namespace; }
/** * {@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); }
protected function execute(InputInterface $input, OutputInterface $output) { $dialog = $this->getDialogHelper(); $entity = Validators::validateEntityName($input->getOption('entity')); list($bundle, $entity) = $this->parseShortcutNotation($entity); $field = $input->getOption('field'); print $bundle . ":" . $entity . "->" . $field; $repo = $this->getContainer()->get('doctrine')->getRepository($bundle . ":" . $entity); $em = $this->getContainer()->get('doctrine')->getManager(); $ids = $em->createQuery("SELECT e.id FROM " . $bundle . ":" . $entity . " e ORDER BY e.id ASC")->setMaxResults(16000)->getArrayResult(); foreach ($ids as $pos => $e) { $toFlush = false; $entity = $repo->findOneById($e['id']); $fileData = $entity->{'get' . ucfirst($field)}(); if (!$fileData) { continue; } $filename = $fileData['dir'] . '/' . $fileData['fileName']; if (file_exists($filename)) { //print "\n exists " . $filename; $byFileNameExists = true; } else { //print "\n NO exists " . $filename; $byFileNameExists = false; } $webDir = $this->getContainer()->getParameter('iphp.web_dir'); $filenameByPath = $webDir . $fileData['path']; if (file_exists($filenameByPath)) { // print "\n By Path exists " . $filenameByPath; $byFilePathExists = true; } else { // print "\n By Path NO exists " . $filenameByPath; $byFilePathExists = false; } print "\n\n " . $entity->getId() . ' ' . (string) $entity; if ($byFilePathExists && $byFileNameExists) { print ": NO PROBLEM"; continue; } if (!$byFilePathExists && $byFileNameExists) { print "\nresave " . $filename; print file_exists($filename) ? " EXISTS" : " NO EXISTS"; $fileObj = new \Symfony\Component\HttpFoundation\File\File($filename); print "\n Obj created"; $entity->{'set' . ucfirst($field)}($fileObj); $em->persist($entity); $toFlush = true; print 'saved'; } if ($pos % 20 == 0 && $toFlush) { $em->flush(); } if ($pos % 100 == 0) { $em->clear(); } } }
/** * @see Command */ protected function execute(InputInterface $input, OutputInterface $output) { $entity = Validators::validateEntityName($input->getArgument('entity')); list($bundle, $entity) = $this->parseShortcutNotation($entity); $entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle) . '\\' . $entity; $metadata = $this->getEntityMetadata($entityClass); $bundle = $this->getApplication()->getKernel()->getBundle($bundle); $generator = $this->getGenerator($bundle); $generator->generate($bundle, $entity, $metadata[0]); $output->writeln(sprintf('The new %s.php class file has been created under %s.', $generator->getClassName(), $generator->getClassPath())); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $questionHelper = $this->getQuestionHelper(); $questionHelper->writeSection($output, 'Admin Tests Generation'); GeneratorUtils::ensureOptionsProvided($input, array('namespace')); $namespace = Validators::validateBundleNamespace($input->getOption('namespace')); $bundle = strtr($namespace, array('\\Bundle\\' => '', '\\' => '')); $bundle = $this->getApplication()->getKernel()->getBundle($bundle); $generator = $this->getGenerator($this->getApplication()->getKernel()->getBundle("KunstmaanGeneratorBundle")); $generator->generate($bundle, $output); }
/** * @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); }
/** * @see Command */ 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; } } $entity = Validators::validateEntityName($input->getOption('entity')); list($bundle, $entity) = $this->parseShortcutNotation($entity); $format = "rest"; $prefix = $this->getRoutePrefix($input, $entity); $forceOverwrite = $input->getOption('overwrite'); $questionHelper->writeSection($output, 'REST api generation'); $entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle) . '\\' . $entity; $metadata = $this->getEntityMetadata($entityClass); $bundle = $this->getContainer()->get('kernel')->getBundle($bundle); $resource = $input->getOption('resource'); $document = $input->getOption('document'); $form = $input->getOption('form'); if ($form) { $entityName = $input->getOption('entity'); $process = new Process("app/console doctrine:generate:form {$entityName}"); $process->run(function ($type, $buffer) { if ('err' === $type) { echo 'ERR > ' . $buffer; } else { echo 'OUT > ' . $buffer; } }); } /** @var DoctrineRESTGenerator $generator */ $generator = $this->getGenerator($bundle); $generator->generate($bundle, $entity, $metadata[0], $prefix, $forceOverwrite, $resource, $document); $output->writeln('Generating the REST api code: <info>OK</info>'); $errors = array(); $runner = $questionHelper->getRunner($output, $errors); // form $this->generateForm($bundle, $entity, $metadata); $output->writeln('Generating the Form code: <info>OK</info>'); // create route $runner($this->updateRouting($questionHelper, $input, $output, $bundle, $format, $entity, $prefix)); $questionHelper->writeGeneratorSummary($output, $errors); }
/** * @see Command */ protected function execute(InputInterface $input, OutputInterface $output) { $questionHelper = $this->getQuestionHelper(); $entity = Validators::validateEntityName($input->getOption('entity')); /** @var TemplateInterface $generator */ $generator = $this->getGenerator(); if ($input->getOption('path')) { $generator->setConfiguration('path', $input->getOption('path')); } $questionHelper->writeSection($output, 'Form generation'); $errors = array(); $runner = $questionHelper->getRunner($output, $errors); $runner($generator->generate($entity)); if (!$input->getOption('no-summary')) { $questionHelper->writeGeneratorSummary($output, $generator->getErrors()); } }
/** * Interacts with the user. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance */ protected function interact(InputInterface $input, OutputInterface $output) { $dialog = $this->getDialogHelper(); $dialog->writeSection($output, 'Welcome to the Kunstmaan admin list generator'); // entity $entity = null; try { $entity = $input->getOption('entity') ? Validators::validateEntityName($input->getOption('entity')) : null; } catch (\Exception $error) { $output->writeln($dialog->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error')); } if (is_null($entity)) { $output->writeln(array('', 'This command helps you to generate an admin list for your entity.', '', 'You must use the shortcut notation like <comment>AcmeBlogBundle:Post</comment>.', '')); $entity = $dialog->askAndValidate($output, $dialog->getQuestion('The entity shortcut name', $entity), array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateEntityName'), false, $entity); $input->setOption('entity', $entity); } }
/** * @see Command */ 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; } } $entity = Validators::validateEntityName($input->getOption('entity')); list($bundle, $entity) = $this->parseShortcutNotation($entity); $format = Validators::validateFormat($input->getOption('format')); $prefix = $this->getRoutePrefix($input, $entity); $withWrite = $input->getOption('with-write'); $forceOverwrite = $input->getOption('overwrite'); $questionHelper->writeSection($output, 'CRUD generation'); try { $entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle) . '\\' . $entity; $metadata = $this->getEntityMetadata($entityClass); } catch (\Exception $e) { throw new \RuntimeException(sprintf('Entity "%s" does not exist in the "%s" bundle. Create it with the "doctrine:generate:entity" command and then execute this command again.', $entity, $bundle)); } $bundle = $this->getContainer()->get('kernel')->getBundle($bundle); $generator = $this->getGenerator($bundle); $generator->generate($bundle, $entity, $metadata[0], $format, $prefix, $withWrite, $forceOverwrite); $output->writeln('Generating the CRUD code: <info>OK</info>'); $errors = array(); $runner = $questionHelper->getRunner($output, $errors); // form if ($withWrite) { $output->write('Generating the Form code: '); if ($this->generateForm($bundle, $entity, $metadata)) { $output->writeln('<info>OK</info>'); } else { $output->writeln('<comment>Already exists, skipping</comment>'); } } // routing if ('annotation' != $format) { $runner($this->updateRouting($questionHelper, $input, $output, $bundle, $format, $entity, $prefix)); } $questionHelper->writeGeneratorSummary($output, $errors); }
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()); } }
/** * Executes the command. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance */ protected function execute(InputInterface $input, OutputInterface $output) { $questionHelper = $this->getQuestionHelper(); $questionHelper->writeSection($output, 'Search Page Generation'); GeneratorUtils::ensureOptionsProvided($input, array('namespace')); $namespace = Validators::validateBundleNamespace($input->getOption('namespace')); $bundle = strtr($namespace, array('\\' => '')); $prefix = $input->getOption('prefix'); $createPage = $input->getOption('createpage'); $bundle = $this->getApplication()->getKernel()->getBundle($bundle); $rootDir = $this->getApplication()->getKernel()->getRootDir(); $generator = $this->getGenerator($this->getApplication()->getKernel()->getBundle("KunstmaanGeneratorBundle")); $generator->generate($bundle, $prefix, $rootDir, $createPage, $output); $output->writeln(array('Make sure you update your database first before you test the pagepart:', ' Directly update your database: <comment>app/console doctrine:schema:update --force</comment>', ' Create a Doctrine migration and run it: <comment>app/console doctrine:migrations:diff && app/console doctrine:migrations:migrate</comment>')); if ($createPage) { $output->writeln(' New DataFixtures were created. You can load them via: <comment>app/console doctrine:fixtures:load --fixtures=src/' . str_replace('\\', '/', $bundle->getNamespace()) . '/DataFixtures/ORM/SearchPageGenerator/ --append</comment>'); } $output->writeln(''); }
/** * @throws \InvalidArgumentException When the bundle doesn't end with Bundle (Example: "Bundle/MySampleBundle") */ protected function execute(InputInterface $input, OutputInterface $output) { $questionHelper = $this->getQuestionHelper(); $entity = Validators::validateEntityName($input->getOption('entity')); list($bundle, $entity) = $this->parseShortcutNotation($entity); $format = Validators::validateFormat($input->getOption('format')); $fields = $this->parseFields($input->getOption('fields')); $questionHelper->writeSection($output, 'Entity generation'); $bundle = $this->getContainer()->get('kernel')->getBundle($bundle); /** @var DoctrineEntityGenerator $generator */ $generator = $this->getGenerator(); $generatorResult = $generator->generate($bundle, $entity, $format, array_values($fields)); $output->writeln(sprintf('> Generating entity class <info>%s</info>: <comment>OK!</comment>', $this->makePathRelative($generatorResult->getEntityPath()))); $output->writeln(sprintf('> Generating repository class <info>%s</info>: <comment>OK!</comment>', $this->makePathRelative($generatorResult->getRepositoryPath()))); if ($generatorResult->getMappingPath()) { $output->writeln(sprintf('> Generating mapping file <info>%s</info>: <comment>OK!</comment>', $this->makePathRelative($generatorResult->getMappingPath()))); } $questionHelper->writeGeneratorSummary($output, array()); }
/** * Executes the command. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance */ protected function execute(InputInterface $input, OutputInterface $output) { $dialog = $this->getDialogHelper(); $dialog->writeSection($output, 'Article Generation'); GeneratorUtils::ensureOptionsProvided($input, array('namespace', 'entity')); $namespace = Validators::validateBundleNamespace($input->getOption('namespace')); $bundle = strtr($namespace, array('\\' => '')); $entity = ucfirst($input->getOption('entity')); $prefix = $input->getOption('prefix'); $dummydata = $input->getOption('dummydata'); $bundle = $this->getApplication()->getKernel()->getBundle($bundle); $generator = $this->getGenerator($this->getApplication()->getKernel()->getBundle("KunstmaanGeneratorBundle")); $generator->generate($bundle, $entity, $prefix, $dummydata, $output); $output->writeln(array('Make sure you update your database first before using the created entities:', ' Directly update your database: <comment>app/console doctrine:schema:update --force</comment>', ' Create a Doctrine migration and run it: <comment>app/console doctrine:migrations:diff && app/console doctrine:migrations:migrate</comment>')); if ($dummydata) { $output->writeln(' New DataFixtures were created. You can load them via: <comment>app/console doctrine:fixtures:load --fixtures=src/' . str_replace('\\', '/', $bundle->getNamespace()) . '/DataFixtures/ORM/ArticleGenerator/ --append</comment>'); } $output->writeln(''); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $entity = Validators::validateEntityName($input->getArgument('entity')); list($bundle, $entity) = $this->parseShortcutNotation($entity); $fields = Fields::parseFields($input->getOption('fields')); $clientSide = $input->getOption('client-side'); $ajaxUrl = $input->getOption('ajax-url'); $entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle) . "\\" . $entity; $metadata = $this->getEntityMetadata($entityClass); if (count($metadata[0]->identifier) > 1) { throw new RuntimeException('The datatable class generator does not support entities with multiple primary keys.'); } if (0 == count($fields)) { $fields = $this->getFieldsFromMetadata($metadata[0]); } $bundle = $this->getContainer()->get('kernel')->getBundle($bundle); /** @var \Sg\DatatablesBundle\Generator\DatatableGenerator $generator */ $generator = $this->getGenerator($bundle); $generator->generate($bundle, $entity, $fields, $clientSide, $ajaxUrl); $output->writeln(sprintf('The new datatable %s.php class file has been created under %s.', $generator->getClassName(), $generator->getClassPath())); }
/** * @throws \InvalidArgumentException When the bundle doesn't end with Bundle (Example: "Bundle/MySampleBundle") */ 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; } } $entity = Validators::validateEntityName($input->getOption('entity')); list($bundle, $entity) = $this->parseShortcutNotation($entity); $format = Validators::validateFormat($input->getOption('format')); $fields = $this->parseFields($input->getOption('fields')); $questionHelper->writeSection($output, 'Entity generation'); $bundle = $this->getContainer()->get('kernel')->getBundle($bundle); $generator = $this->getGenerator(); $generator->generate($bundle, $entity, $format, array_values($fields), $input->getOption('with-repository')); $output->writeln('Generating the entity code: <info>OK</info>'); $questionHelper->writeGeneratorSummary($output, array()); }
/** * @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); }
/** * Execute * * @param InputInterface $input The Input Interface * @param OutputInterface $output The Output Interface * * @return int */ 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; } } $entity = Validators::validateEntityName($input->getOption('entity')); list($bundle, $entity) = $this->parseShortcutNotation($entity); $dialog->writeSection($output, 'CRUD generation'); $entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle) . '\\' . $entity; $mf = $this->getContainer()->get('doctrine.orm.entity_manager')->getMetadataFactory(); $metadata = $mf->getMetadataFor($entityClass); // Custom route_prefix $prefix = $this->getRoutePrefix($input, str_replace('Bundle\\Entity', '\\' . $this->application, $entityClass)); $bundle = $this->getContainer()->get('kernel')->getBundle($bundle); // Check if we create a Translation or not $translation = array(); if (isset($metadata->associationMappings['translations'])) { $translationEntityClass = $metadata->associationMappings['translations']['targetEntity']; $entityTranslation = str_replace('\\', '', explode('\\Entity', $translationEntityClass)); $entityTranslation = $entityTranslation[1]; $translationMetadata = $mf->getMetadataFor($translationEntityClass); $translation['entity'] = $entityTranslation; $translation['entityClass'] = $translationEntityClass; $translation['metadata'] = $translationMetadata; } // Generate the controller $generator = $this->getGenerator(); $generator->generate($bundle, $entity, $metadata, 'yml', $prefix, true, true, $this->application, $translation, $input->getOption('use-datagrid')); $output->writeln('Generating the Controller code: <info>OK</info>'); $errors = array(); // form $this->generateForm($bundle, $entity, $metadata, $translation); $output->writeln('Generating the Form code: <info>OK</info>'); $dialog->writeGeneratorSummary($output, $errors); }
protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $entity = Validators::validateEntityName($input->getArgument('entity')); list($bundle, $entity) = $this->parseShortcutNotation($entity); // $entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle).'\\'.$entity; // $metadata = $this->getEntityMetadata($entityClass); $bundle = $this->getApplication()->getKernel()->getBundle($bundle); $entityPath = $bundle->getPath() . '/Entity/' . $entity . '.php'; $entityContent = file_get_contents($entityPath); $extension = '\\SKCMS\\CoreBundle\\Form\\EntityType'; if (preg_match('#SKBasePage#', $entityContent)) { $extension = '\\SKCMS\\CoreBundle\\Form\\PageType'; } $dirPath = $bundle->getPath() . '/Form'; $classPath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'Type.php'; $classModifier = $this->getContainer()->get('skcms_core.classmodifier'); $classModifier->addExtends($classPath, $extension); $classModifier->parentBuildForm($classPath); $classModifier->removeLineContaining($classPath, ['slug', 'userCreate', 'userUpdate', 'creationDate', 'updateDate', 'draft', 'position']); $output->writeln($classPath . ' skized'); }
/** * @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); }