本文整理汇总了PHP中Sensio\Bundle\GeneratorBundle\Command\Validators::validateBundleNamespace方法的典型用法代码示例。如果您正苦于以下问题:PHP Validators::validateBundleNamespace方法的具体用法?PHP Validators::validateBundleNamespace怎么用?PHP Validators::validateBundleNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sensio\Bundle\GeneratorBundle\Command\Validators
的用法示例。
在下文中一共展示了Validators::validateBundleNamespace方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: askForNamespace
/**
* 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;
}
示例2: execute
/**
* 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);
}
示例3: execute
/**
* {@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);
}
示例4: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
// Start question helper
$questionHelper = $this->getQuestionHelper();
$questionHelper->writeSection($output, 'Welcome to the united bundle generator!');
// get namespace
$namespace = $input->getOption('namespace');
$question = new Question($questionHelper->getQuestion('Bundle namespace', $namespace), $namespace);
$question->setValidator(function ($answer) {
return Validators::validateBundleNamespace($answer, true);
});
$namespace = $questionHelper->ask($input, $output, $question);
$input->setOption('namespace', $namespace);
}
示例5: 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);
}
示例6: execute
/**
* 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('');
}
示例7: execute
/**
* 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('');
}
示例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)
{
$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);
}
示例9: 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;
}
$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 = $dialog->getRunner($output, $errors);
// routing
$runner($this->updateRouting($dialog, $input, $output, $bundle, $format));
$dialog->writeGeneratorSummary($output, $errors);
}
示例10: 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), '']);
}
示例11: 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), ''));
}
示例12: 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;
}
示例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);
}
示例14: getGenerationParams
/**
* 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);
}