當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Validators::validateFormat方法代碼示例

本文整理匯總了PHP中Sensio\Bundle\GeneratorBundle\Command\Validators::validateFormat方法的典型用法代碼示例。如果您正苦於以下問題:PHP Validators::validateFormat方法的具體用法?PHP Validators::validateFormat怎麽用?PHP Validators::validateFormat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Sensio\Bundle\GeneratorBundle\Command\Validators的用法示例。


在下文中一共展示了Validators::validateFormat方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: execute

 /**
  * @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);
 }
開發者ID:r0ma,項目名稱:SensioGeneratorBundle,代碼行數:37,代碼來源:GenerateDoctrineCrudCommand.php

示例2: execute

 /**
  * @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());
 }
開發者ID:orkestro,項目名稱:orkestro,代碼行數:29,代碼來源:GenerateOrkestroEntityCommand.php

示例3: execute

 /**
  * @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);
 }
開發者ID:iicc,項目名稱:RedKiteCmsBundle,代碼行數:54,代碼來源:BaseGenerateBundle.php

示例4: execute

 /**
  * @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);
 }
開發者ID:OskarStark,項目名稱:SensioGeneratorBundle,代碼行數:47,代碼來源:GenerateDoctrineCrudCommand.php

示例5: execute

 /**
  * @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());
 }
開發者ID:OskarStark,項目名稱:SensioGeneratorBundle,代碼行數:22,代碼來源:GenerateDoctrineEntityCommand.php

示例6: execute

 /**
  * @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());
 }
開發者ID:Dren-x,項目名稱:mobit,代碼行數:24,代碼來源:GenerateDoctrineEntityCommand.php

示例7: execute

 /**
  * @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);
 }
開發者ID:ErikZigo,項目名稱:syrup,代碼行數:46,代碼來源:GenerateComponentCommand.php

示例8: execute

 /**
  * @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);
 }
開發者ID:nibsirahsieu,項目名稱:AdmingeneratorGeneratorBundle,代碼行數:43,代碼來源:GenerateAdminAdminCommand.php

示例9: interact

 /**
  * Collect options and arguments.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return void
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getQuestionHelper();
     $questionHelper->writeSection($output, 'Welcome to the Victoire widget bundle generator');
     ///////////////////////
     //                   //
     //   Create Bundle   //
     //                   //
     ///////////////////////
     // namespace
     $namespace = null;
     try {
         $namespace = $input->getOption('namespace') ? Validators::validateBundleNamespace($input->getOption('namespace')) : null;
     } catch (\Exception $error) {
         $output->writeln($questionHelper->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
     }
     if (null === $namespace) {
         $output->writeln(['', 'Your application code must be written in <comment>widget bundles</comment>. This command helps', 'you generate them easily.', '', 'Each widget is hosted under a namespace (like <comment>Victoire/Widget/YourAwesomeWidgetNameBundle</comment>).', '', 'If you want for example a BlogWidget, the Widget Name should be Blog']);
         $question = new Question($questionHelper->getQuestion('Widget name', $input->getOption('bundle-name')));
         $question->setValidator(function ($answer) {
             return self::validateWidgetName($answer, false);
         });
         $name = $questionHelper->ask($input, $output, $question);
         $bundle = 'VictoireWidget' . $name . 'Bundle';
         $input->setOption('bundle-name', $bundle);
         $namespace = 'Victoire\\Widget\\' . $name . 'Bundle';
         $input->setOption('namespace', $namespace);
     }
     $orgname = $input->getOption('orgname');
     if (null === $orgname) {
         $output->writeln(['', 'A composer.json file will be generated, we need to know under which organisation you will publish the widget', '', 'The default organisation will be friendsofvictoire']);
         $question = new Question($questionHelper->getQuestion('Under which organisation do you want to publish your widget ?', 'friendsofvictoire'), 'friendsofvictoire');
         $orgname = $questionHelper->ask($input, $output, $question);
     }
     $input->setOption('orgname', $orgname);
     $parent = $input->getOption('parent');
     $question = new ConfirmationQuestion($questionHelper->getQuestion('Does your widget extends another widget ?', 'no', '?'), false);
     if (null === $parent && $questionHelper->ask($input, $output, $question)) {
         $output->writeln(['', 'A widget can extends another to reproduce it\'s behavior', '', 'If you wabt to do so, please give the name of the widget to extend', '', 'If you want to extends the TestWidget, the widget name should be Test']);
         $question = new Question($questionHelper->getQuestion('Parent widget name', false));
         $question->setValidator(function ($answer) {
             return self::validateWidgetName($answer, false);
         });
         $parent = $questionHelper->ask($input, $output, $question);
         $input->setOption('parent', $parent);
         $packagistParentName = 'friendsofvictoire/' . strtolower($parent) . '-widget';
         $question = new Question($questionHelper->getQuestion('Parent widget packagist name', $packagistParentName));
         $parent = $questionHelper->ask($input, $output, $question);
         $input->setOption('packagist-parent-name', $packagistParentName);
     }
     $dir = dirname($this->getContainer()->getParameter('kernel.root_dir')) . '/src';
     $output->writeln(['', 'The bundle can be generated anywhere. The suggested default directory uses', 'the standard conventions.', '']);
     $question = new Question($questionHelper->getQuestion('Target directory', $dir), $dir);
     $question->setValidator(function ($dir) use($bundle, $namespace) {
         return Validators::validateTargetDir($dir, $bundle, $namespace);
     });
     $dir = $questionHelper->ask($input, $output, $question);
     $input->setOption('dir', $dir);
     // format
     $format = null;
     try {
         $format = $input->getOption('format') ? Validators::validateFormat($input->getOption('format')) : null;
     } catch (\Exception $error) {
         $output->writeln($questionHelper->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
     }
     if (null === $format) {
         $output->writeln(['', 'Determine the format to use for the generated configuration.', '']);
         $question = new Question($questionHelper->getQuestion('Configuration format (yml, xml, php, or annotation)', 'annotation'), 'annotation');
         $question->setValidator(['Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateFormat']);
         $format = $questionHelper->ask($input, $output, $question);
         $input->setOption('format', $format);
     }
     $input->setOption('structure', false);
     $contentResolver = $input->getOption('content-resolver');
     $question = new ConfirmationQuestion($questionHelper->getQuestion('Do you want to customize widget rendering logic ?', 'no', '?'), false);
     if (!$contentResolver && $questionHelper->ask($input, $output, $question)) {
         $contentResolver = true;
     }
     $input->setOption('content-resolver', $contentResolver);
     ///////////////////////
     //                   //
     //   Create Entity   //
     //                   //
     ///////////////////////
     $input->setOption('fields', $this->addFields($input, $output, $questionHelper));
     $entity = 'Widget' . $name;
     $input->setOption('entity', $bundle . ':' . $entity);
     // summary
     $output->writeln(['', $this->getHelper('formatter')->formatBlock('Summary before generation', 'bg=blue;fg=white', true), '', sprintf("You are going to generate a \"<info>%s\\%s</info>\" widget bundle\nin \"<info>%s</info>\" using the \"<info>%s</info>\" format.", $namespace, $bundle, $dir, $format), '']);
 }
開發者ID:global01,項目名稱:victoire,代碼行數:98,代碼來源:CreateWidgetCommand.php

示例10: interact

 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getQuestionHelper();
     $questionHelper->writeSection($output, 'Welcome to the Symfony2 bundle generator');
     // namespace
     $namespace = null;
     try {
         // validate the namespace option (if any) but don't require the vendor namespace
         $namespace = $input->getOption('namespace') ? Validators::validateBundleNamespace($input->getOption('namespace'), false) : null;
     } catch (\Exception $error) {
         $output->writeln($questionHelper->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
     }
     if (null === $namespace) {
         $output->writeln(array('', 'Your application code must be written in <comment>bundles</comment>. This command helps', 'you generate them easily.', '', 'Each bundle is hosted under a namespace (like <comment>Acme/Bundle/BlogBundle</comment>).', 'The namespace should begin with a "vendor" name like your company name, your', 'project name, or your client name, followed by one or more optional category', 'sub-namespaces, and it should end with the bundle name itself', '(which must have <comment>Bundle</comment> as a suffix).', '', 'See http://symfony.com/doc/current/cookbook/bundles/best_practices.html#index-1 for more', 'details on bundle naming conventions.', '', 'Use <comment>/</comment> instead of <comment>\\ </comment> for the namespace delimiter to avoid any problem.', ''));
         $acceptedNamespace = false;
         while (!$acceptedNamespace) {
             $question = new Question($questionHelper->getQuestion('Bundle namespace', $input->getOption('namespace')), $input->getOption('namespace'));
             $question->setValidator(function ($answer) {
                 return Validators::validateBundleNamespace($answer, false);
             });
             $namespace = $questionHelper->ask($input, $output, $question);
             // mark as accepted, unless they want to try again below
             $acceptedNamespace = true;
             // see if there is a vendor namespace. If not, this could be accidental
             if (false === strpos($namespace, '\\')) {
                 // language is (almost) duplicated in Validators
                 $msg = array();
                 $msg[] = '';
                 $msg[] = sprintf('The namespace sometimes contain a vendor namespace (e.g. <info>VendorName/BlogBundle</info> instead of simply <info>%s</info>).', $namespace, $namespace);
                 $msg[] = 'If you\'ve *did* type a vendor namespace, try using a forward slash <info>/</info> (<info>Acme/BlogBundle</info>)?';
                 $msg[] = '';
                 $output->writeln($msg);
                 $question = new ConfirmationQuestion($questionHelper->getQuestion(sprintf('Keep <comment>%s</comment> as the bundle namespace (choose no to try again)?', $namespace), 'yes'), true);
                 $acceptedNamespace = $questionHelper->ask($input, $output, $question);
             }
         }
         $input->setOption('namespace', $namespace);
     }
     // bundle name
     $bundle = null;
     try {
         $bundle = $input->getOption('bundle-name') ? Validators::validateBundleName($input->getOption('bundle-name')) : null;
     } catch (\Exception $error) {
         $output->writeln($questionHelper->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
     }
     if (null === $bundle) {
         $bundle = strtr($namespace, array('\\Bundle\\' => '', '\\' => ''));
         $output->writeln(array('', 'In your code, a bundle is often referenced by its name. It can be the', 'concatenation of all namespace parts but it\'s really up to you to come', 'up with a unique name (a good practice is to start with the vendor name).', 'Based on the namespace, we suggest <comment>' . $bundle . '</comment>.', ''));
         $question = new Question($questionHelper->getQuestion('Bundle name', $bundle), $bundle);
         $question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateBundleName'));
         $bundle = $questionHelper->ask($input, $output, $question);
         $input->setOption('bundle-name', $bundle);
     }
     // target dir
     $dir = null;
     try {
         $dir = $input->getOption('dir') ? Validators::validateTargetDir($input->getOption('dir'), $bundle, $namespace) : null;
     } catch (\Exception $error) {
         $output->writeln($questionHelper->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
     }
     if (null === $dir) {
         $dir = dirname($this->getContainer()->getParameter('kernel.root_dir')) . '/src';
         $output->writeln(array('', 'The bundle can be generated anywhere. The suggested default directory uses', 'the standard conventions.', ''));
         $question = new Question($questionHelper->getQuestion('Target directory', $dir), $dir);
         $question->setValidator(function ($dir) use($bundle, $namespace) {
             return Validators::validateTargetDir($dir, $bundle, $namespace);
         });
         $dir = $questionHelper->ask($input, $output, $question);
         $input->setOption('dir', $dir);
     }
     // format
     $format = null;
     try {
         $format = $input->getOption('format') ? Validators::validateFormat($input->getOption('format')) : null;
     } catch (\Exception $error) {
         $output->writeln($questionHelper->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
     }
     if (null === $format) {
         $output->writeln(array('', 'Determine the format to use for the generated configuration.', ''));
         $question = new Question($questionHelper->getQuestion('Configuration format (yml, xml, php, or annotation)', $input->getOption('format')), $input->getOption('format'));
         $question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateFormat'));
         $format = $questionHelper->ask($input, $output, $question);
         $input->setOption('format', $format);
     }
     // optional files to generate
     $output->writeln(array('', 'To help you get started faster, the command can generate some', 'code snippets for you.', ''));
     $structure = $input->getOption('structure');
     $question = new ConfirmationQuestion($questionHelper->getQuestion('Do you want to generate the whole directory structure', 'no', '?'), false);
     if (!$structure && $questionHelper->ask($input, $output, $question)) {
         $structure = true;
     }
     $input->setOption('structure', $structure);
     // summary
     $output->writeln(array('', $this->getHelper('formatter')->formatBlock('Summary before generation', 'bg=blue;fg=white', true), '', sprintf("You are going to generate a \"<info>%s\\%s</info>\" bundle\nin \"<info>%s</info>\" using the \"<info>%s</info>\" format.", $namespace, $bundle, $dir, $format), ''));
 }
開發者ID:BusinessCookies,項目名稱:CoffeeMachineProject,代碼行數:95,代碼來源:GenerateBundleCommand.php

示例11: createBundleObject

 /**
  * Creates the Bundle object based on the user's (non-interactive) input.
  *
  * @param InputInterface $input
  *
  * @return Bundle
  */
 protected function createBundleObject(InputInterface $input)
 {
     foreach (array('namespace', 'dir') as $option) {
         if (null === $input->getOption($option)) {
             throw new \RuntimeException(sprintf('The "%s" option must be provided.', $option));
         }
     }
     $shared = $input->getOption('shared');
     $namespace = Validators::validateBundleNamespace($input->getOption('namespace'), $shared);
     if (!($bundleName = $input->getOption('bundle-name'))) {
         $bundleName = strtr($namespace, array('\\' => ''));
     }
     $bundleName = Validators::validateBundleName($bundleName);
     $dir = $input->getOption('dir');
     if (null === $input->getOption('format')) {
         $input->setOption('format', 'annotation');
     }
     $format = Validators::validateFormat($input->getOption('format'));
     // an assumption that the kernel root dir is in a directory (like app/)
     $projectRootDirectory = $this->getContainer()->getParameter('kernel.root_dir') . '/..';
     if (!$this->getContainer()->get('filesystem')->isAbsolutePath($dir)) {
         $dir = $projectRootDirectory . '/' . $dir;
     }
     // add trailing / if necessary
     $dir = '/' === substr($dir, -1, 1) ? $dir : $dir . '/';
     $bundle = new Bundle($namespace, $bundleName, $dir, $format, $shared);
     // not shared - put the tests in the root
     if (!$shared) {
         $testsDir = $projectRootDirectory . '/tests/' . $bundleName;
         $bundle->setTestsDirectory($testsDir);
     }
     return $bundle;
 }
開發者ID:WilBenShu,項目名稱:digital_pilot,代碼行數:40,代碼來源:GenerateBundleCommand.php

示例12: execute

 /**
  * @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);
 }
開發者ID:joshuataylor,項目名稱:PUGXGeneratorBundle,代碼行數:73,代碼來源:GenerateDoctrineCrudCommand.php

示例13: createBundleObject

 /**
  * Creates the Bundle object based on the user's (non-interactive) input.
  *
  * @param InputInterface $input
  *
  * @return Bundle
  */
 protected function createBundleObject(InputInterface $input)
 {
     foreach (array('namespace', 'dir') as $option) {
         if (null === $input->getOption($option)) {
             throw new \RuntimeException(sprintf('The "%s" option must be provided.', $option));
         }
     }
     $shared = $input->getOption('shared');
     $namespace = Validators::validateBundleNamespace($input->getOption('namespace'), $shared);
     if (!($bundleName = $input->getOption('bundle-name'))) {
         $bundleName = strtr($namespace, array('\\' => ''));
     }
     $bundleName = Validators::validateBundleName($bundleName);
     $dir = $input->getOption('dir');
     if (null === $input->getOption('format')) {
         $input->setOption('format', 'annotation');
     }
     $format = Validators::validateFormat($input->getOption('format'));
     if (!$this->getContainer()->get('filesystem')->isAbsolutePath($dir)) {
         $dir = getcwd() . '/' . $dir;
     }
     // add trailing / if necessary
     $dir = '/' === substr($dir, -1, 1) ? $dir : $dir . '/';
     return new Bundle($namespace, $bundleName, $dir, $format, $shared);
 }
開發者ID:startupz,項目名稱:OroGeneratorBundle,代碼行數:32,代碼來源:GenerateBundleCommand.php

示例14: execute

 /**
  * @see Command
  *
  * @throws \InvalidArgumentException When namespace doesn't end with Bundle
  * @throws \RuntimeException         When bundle can't be executed
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getQuestionHelper();
     if ($input->isInteractive()) {
         $question = new ConfirmationQuestion('Do you confirm generation?', true);
         if (!$questionHelper->ask($input, $output, $question)) {
             $output->writeln('<error>Command aborted</error>');
             return 1;
         }
     }
     foreach (array('namespace', 'dir') as $option) {
         if (null === $input->getOption($option)) {
             throw new \RuntimeException(sprintf('The "%s" option must be provided.', $option));
         }
     }
     $namespace = Validators::validateBundleNamespace($input->getOption('namespace'));
     if (!($bundle = $input->getOption('bundle-name'))) {
         $bundle = strtr($namespace, array('\\' => ''));
     }
     $bundle = Validators::validateBundleName($bundle);
     $dir = Validators::validateTargetDir($input->getOption('dir'), $bundle, $namespace);
     $format = Validators::validateFormat($input->getOption('format'));
     $structure = $input->getOption('structure');
     $questionHelper->writeSection($output, 'Bundle generation');
     if (!$this->getContainer()->get('filesystem')->isAbsolutePath($dir)) {
         $dir = getcwd() . '/' . $dir;
     }
     $generatorName = $input->getOption('generator');
     $modelName = $input->getOption('model-name');
     $generator = $this->createGenerator();
     $generator->setGenerator($generatorName);
     $generator->setPrefix($input->getOption('prefix'));
     $generator->generate($namespace, $bundle, $dir, $format, $structure, $generatorName, $modelName);
     $output->writeln('Generating the bundle code: <info>OK</info>');
     $errors = array();
     $runner = $questionHelper->getRunner($output, $errors);
     // check that the namespace is already autoloaded
     $runner($this->checkAutoloader($output, $namespace, $bundle, $dir));
     // register the bundle in the Kernel class
     $runner($this->updateKernel($questionHelper, $input, $output, $this->getContainer()->get('kernel'), $namespace, $bundle));
     // routing
     $runner($this->updateRouting($questionHelper, $input, $output, $bundle, $format));
     $questionHelper->writeGeneratorSummary($output, $errors);
 }
開發者ID:Restless-ET,項目名稱:GeneratorBundle,代碼行數:50,代碼來源:GenerateAdminCommand.php


注:本文中的Sensio\Bundle\GeneratorBundle\Command\Validators::validateFormat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。