コード例 #1
0
 /**
  * {@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>', ''));
 }
コード例 #2
0
 /**
  * @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());
 }
コード例 #3
0
 /**
  * @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());
     }
 }
コード例 #4
0
 /**
  * @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);
 }
コード例 #5
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);
 }
コード例 #6
0
 /**
  * @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);
 }
コード例 #7
0
 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();
         }
     }
 }
コード例 #8
0
 /**
  * @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()));
 }
コード例 #9
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     Validators::validateEntityName($input->getOption('entity'));
     $dialog = $this->getDialogHelper();
     if ($input->getOption('trait')) {
         if (PHP_MAJOR_VERSION < 5 || PHP_MINOR_VERSION < 4) {
             throw new \RuntimeException('You need PHP > 5.4 to use trait feature');
         }
     }
     if (null === $input->getOption('controller')) {
         throw new \RuntimeException('The controller option must be provided.');
     }
     list($bundle, $controller) = $this->parseShortcutNotation($input->getOption('controller'));
     /** @var Bundle $bundle */
     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 exists.</>', $bundle));
         }
     }
     $dialog->writeSection($output, 'Controller generation: ' . $controller . 'Controller (' . $bundle->getName() . ')');
     /** @var RestControllerGenerator $generator */
     $generator = $this->getGenerator($bundle);
     if ($input->getOption('trait')) {
         $output->writeln("<info>Generating Controller with Traits</info>");
         $generator->setUseTrait(true);
         $generator->generate($bundle, $controller, '', '');
         $output->writeln("<info>Trait Controller Generated</info>");
         $generator->setUseTrait(false);
         $generator->setTemplateFile('UseTraitController.php');
         try {
             $generator->generate($bundle, $controller, '', '');
             $output->writeln("<info>Controller Generated</info>");
         } catch (\RuntimeException $e) {
             $output->writeln("<info>Controller Skipped</info>");
         }
     } else {
         $generator->generate($bundle, $controller, '', '');
         $output->writeln("<info>Controller Generated</info>");
     }
     $output->writeln('Generating the bundle code: <info>OK</info>');
     $dialog->writeGeneratorSummary($output, array());
 }
コード例 #10
0
 /**
  * @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());
     }
 }
コード例 #11
0
 /**
  * @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);
 }
コード例 #12
0
 /**
  * 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);
     }
 }
コード例 #13
0
 /**
  * @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);
 }
 /**
  * @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());
 }
コード例 #15
0
 /**
  * @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());
 }
コード例 #16
0
 /**
  * {@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()));
 }
コード例 #17
0
 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');
 }
コード例 #18
0
 /**
  * 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);
 }
コード例 #19
0
 /**
  * @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);
     $prefix = $this->getRoutePrefix($input, $entity);
     $forceOverwrite = $input->getOption('overwrite');
     $dialog->writeSection($output, 'REST api generation');
     $entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle) . '\\' . $entity;
     $metadata = $this->getEntityMetadata($entityClass);
     $bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
     $generator = $this->getGenerator($bundle);
     $generator->generate($bundle, $entity, $metadata[0], $prefix, $forceOverwrite);
     $output->writeln('Generating the REST api code: <info>OK</info>');
     $errors = array();
     $runner = $dialog->getRunner($output, $errors);
     // form
     $dialog->writeSection($output, 'Form generation');
     $this->generateForm($bundle, $entity, $metadata);
     $output->writeln('Generating the Form code: <info>OK</info>');
     $dialog->writeSection($output, 'Routing generation');
     $runner($this->updateRouting($dialog, $input, $output, $bundle, $entity, $prefix));
     $dialog->writeSection($output, 'Entity manager service generation');
     $runner($this->generateManager($dialog, $input, $output, $bundle, $metadata, $entity, $this->getManagersFile($input)));
     if ($this->getContainer()->has('sonata.admin.pool')) {
         $dialog->writeSection($output, 'Sonata admin generation');
         $runner($this->generateAdmin($dialog, $input, $output, $bundle, $metadata, $entity, $this->getAdminFile($input)));
     }
     $dialog->writeGeneratorSummary($output, $errors);
 }
コード例 #20
0
 /**
  * {@inheritdoc}
  */
 public function validateResourceName($resourceName)
 {
     Validators::validateEntityName($resourceName);
 }
コード例 #21
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $calledClass = get_called_class();
     $input->setOption('format', 'annotation');
     //        $input->setOption('with-repository', true);
     parent::execute($input, $output);
     $classModifier = $this->getContainer()->get('skcms_core.classmodifier');
     //Direct grabbed from parent function
     $entity = Validators::validateEntityName($input->getOption('entity'));
     list($bundle, $entity) = $this->parseShortcutNotation($entity);
     $bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
     $entityPath = $bundle->getPath() . '/Entity/' . str_replace('\\', '/', $entity) . '.php';
     $classModifier->addExtends($entityPath, $calledClass::CLASS_PARENT);
     $classModifier->privateToProtected($entityPath);
     $output->writeln(sprintf('SKize entity : ' . $entity));
     //        if ($input->getOption('with-repository') == true)
     //        {
     $repositoryPath = $bundle->getPath() . '/Repository/' . str_replace('\\', '/', $entity) . 'Repository.php';
     $output->writeln(sprintf('SKize repository' . $repositoryPath));
     $classModifier->addExtends($repositoryPath, $calledClass::REPO_PARENT, true);
     //        }
     return;
     //Add to menu configuration
     $doctrine = $this->getContainer()->get('doctrine');
     $namespace = $doctrine->getAliasNamespace();
     $questionHelper = $this->getQuestionHelper();
     $defaultAnswer = array('yes');
     $question = new ConfirmationQuestion($questionHelper->getQuestion('Would you like to add it to the admin menu', $input->getOption('add-to-menu') ? 'yes' : 'no', '?'), $input->getOption('add-to-menu'));
     $add = $questionHelper->ask($input, $output, $question);
     if ($add == true) {
         $defaultAnswer = array(str_replace('\\', '/', $entity));
         $question = new Question($questionHelper->getQuestion('Wich beautiful name would you like to give it', $input->getOption('beauty-name')), $input->getOption('beauty-name'));
         $question->setAutocompleterValues($defaultAnswer);
         $beautyName = $questionHelper->ask($input, $output, $question);
         $loader = new \Symfony\Component\Yaml\Yaml();
         $config = $loader->parse(__DIR__ . '/../../../../../../app/config/config.yml');
         $menus = $config['skcms_admin']['menuGroups'];
         $possibleAnswers = [];
         foreach ($menus as $menuName => $menu) {
             $possibleAnswers[] = $menuName;
         }
         $question = new Question($questionHelper->getQuestion('In wich menu would you like to diplay it ? (' . implode(',', $possibleAnswers) . ')', $input->getOption('menu-group')), $input->getOption('menu-group'));
         $menuNameChoosed = $questionHelper->ask($input, $output, $question);
         if (array_key_exists($menuNameChoosed, $config['skcms_admin']['menuGroups'])) {
         }
         $menuIdChoosed = $config['skcms_admin']['menuGroups'][$menuNameChoosed]['id'];
         dump($bundle->getContainer());
         dump($entity);
         die;
         //            $entity =
         //                    [
         //                      str_replace('\\', '/', $entity)=>
         //                        [
         //                            'name'=> str_replace('\\', '/', $entity),
         //                            'beautyName'=> $beautyName,
         //                            'bundle': $bundle->getName(),
         //
         //
         //            class: \BES\CoreBundle\Entity\Page
         //            form: \BES\CoreBundle\Form\PageType
         //            menuGroup: 1
         //            listProperties:
         //                name:
         //                    dataName: 'title'
         //                    beautyName: 'Titre'
         //                    type: 'string'
         //                    ];
     }
 }
コード例 #22
0
 /**
  * The magic
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->isInteractive()) {
         if (!$this->getQuestionHelper()->ask($input, $output, new ConfirmationQuestion('Do you confirm generation of the ' . $this->getFileTypeCreated() . '? ', false))) {
             $output->writeln('<error>Command aborted</error>');
             return 1;
         }
     }
     $this->entity = Validators::validateEntityName($input->getArgument('entity'));
     list($bundle, $entity) = $this->parseShortcutNotation($this->entity);
     $entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle) . '\\' . $entity;
     $metadata = $this->getEntityMetadata($entityClass);
     $bundle = $this->getApplication()->getKernel()->getBundle($bundle);
     $generator = $this->getGenerator();
     $generator->setFilesystem($this->getContainer()->get('filesystem'));
     try {
         $this->setOptions($input);
         $generator->generate($bundle, $entity, $metadata[0], $this->getOptions());
         $output->writeln(sprintf('<info>The new %s %s file has been created under %s.</info>', $generator->getGeneratedName(), $this->getFileTypeCreated(), $generator->getFilePath()));
     } catch (\Exception $e) {
         $output->writeln("<error>" . $this->getFailureMessage($e) . "</error>");
     }
 }
コード例 #23
0
 /**
  * @see Command
  */
 protected 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;
         }
     }
     $entity = Validators::validateEntityName($input->getOption('entity'));
     list($alias, $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');
     $layout = $input->getOption('layout');
     // TODO validate
     $bodyBlock = $input->getOption('body-block');
     // TODO validate
     $usePaginator = $input->getOption('use-paginator');
     $theme = $input->getOption('theme');
     // TODO validate
     $withFilter = $input->getOption('with-filter');
     // TODO validate
     $withSort = $input->getOption('with-sort');
     // TODO validate
     $dest = $input->getOption('dest') ?: $bundle;
     // TODO validate
     $fixtures = $input->getOption('fixtures');
     // TODO validate
     if ($withFilter && !$usePaginator) {
         throw new \RuntimeException(sprintf('Cannot use filter without paginator.'));
     }
     $questionHelper->writeSection($output, 'CRUD generation');
     // see https://github.com/sensiolabs/SensioGeneratorBundle/issues/277
     try {
         $entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($alias) . '\\' . $entity;
     } catch (ORMException $e) {
         $entityClass = $alias . '\\' . $entity;
     }
     $metadata = $this->getEntityMetadata($entityClass);
     $bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
     $destBundle = $this->getContainer()->get('kernel')->getBundle($dest);
     $generator = $this->getGenerator($bundle);
     $generator->generate($bundle, $destBundle, $entity, $metadata[0], $format, $prefix, $withWrite, $forceOverwrite, $layout, $bodyBlock, $usePaginator, $theme, $withFilter, $withSort);
     $output->writeln('Generating the CRUD code: <info>OK</info>');
     $errors = array();
     $runner = $questionHelper->getRunner($output, $errors);
     // form
     if ($withWrite) {
         $this->doGenerateForm($bundle, $destBundle, $entity, $metadata);
         $output->writeln('Generating the Form code: <info>OK</info>');
     }
     // filter form
     if ($withFilter) {
         $this->doGenerateFilter($bundle, $destBundle, $entity, $metadata);
         $output->writeln('Generating the Filter code: <info>OK</info>');
     }
     // routing
     if ('annotation' != $format) {
         $runner($this->updateRouting($questionHelper, $input, $output, $bundle, $format, $entity, $prefix));
     }
     // fixtures
     if ($fixtures > 0) {
         $this->doGenerateFixtures($bundle, $destBundle, $entity, $metadata, $fixtures);
         $output->writeln(sprintf('Generating %d fixture%s: <info>OK</info>', $fixtures, $fixtures > 1 ? 's' : ''));
     }
     $questionHelper->writeGeneratorSummary($output, $errors);
 }
 /**
  * @throws \InvalidArgumentException When the bundle doesn't end with Bundle (Example: "Bundle/MySampleBundle")
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($this->confirmGeneration === false) {
         $output->writeln('<error>Command aborted</error>');
         return 1;
     }
     $entity = Validators::validateEntityName($input->getOption('entity'));
     list($bundle, $entity) = $this->parseShortcutNotation($entity);
     $name = $input->getOption('name');
     $ids = $this->parseIds($input->getOption('ids'));
     $order = $input->getOption('order');
     $this->writeSection($output, 'Entity generation');
     /** @var Kernel $kernel */
     $kernel = $this->getContainer()->get('kernel');
     $bundle = $kernel->getBundle($bundle);
     $generator = $this->getGenerator();
     $connectionName = $input->getOption('connectionName');
     $generator->generate($bundle, $entity, $name, array_values($ids), $order, $connectionName);
     $output->writeln('Generating the fixture code: <info>OK</info>');
     //all fine.
     return 0;
 }
コード例 #25
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);
 }
コード例 #26
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);
     }
 }