本文整理汇总了PHP中Sensio\Bundle\GeneratorBundle\Command\Validators::validateBundleName方法的典型用法代码示例。如果您正苦于以下问题:PHP Validators::validateBundleName方法的具体用法?PHP Validators::validateBundleName怎么用?PHP Validators::validateBundleName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sensio\Bundle\GeneratorBundle\Command\Validators
的用法示例。
在下文中一共展示了Validators::validateBundleName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('');
$output->writeln(sprintf('<info>Generation of Crud Rest Controller for "%s" Document in "%s" bundle.</info>', $input->getOption('document'), $input->getOption('bundle')));
$output->writeln('');
$document = $input->getOption('document');
$bundle = $input->getOption('bundle');
$bundle = Validators::validateBundleName($bundle);
try {
$bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
} catch (\Exception $e) {
$output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</>', $bundle));
}
// Get document metadata
$dm = $this->getContainer()->get('doctrine_mongodb.odm.document_manager');
$class_metadata = $dm->getClassMetadata($document);
$generator = $this->getGenerator($this->getContainer()->get('kernel')->getBundle('RedkingCoreRestBundle'));
if ($input->getOption('no-controller') === false) {
$generator->generate($bundle, $class_metadata);
$output->writeln('Generating the CRUD code: <info>OK</info>');
}
if ($input->getOption('no-service') === false) {
$generator->generateServices($bundle, $class_metadata);
$output->writeln('Generating the services: <info>OK</info>');
}
if ($input->getOption('no-test') === false) {
$generator->generateTests($bundle, $class_metadata);
$output->writeln('Generating the functional test: <info>OK</info>');
}
if ($input->getOption('no-route') === false) {
$generator->generateRouting($bundle, $class_metadata);
$output->writeln('Add routing: <info>OK</info>');
}
}
示例2: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getQuestionHelper();
if ($input->isInteractive() && !$input->getOption('no-summary')) {
$question = new Question($questionHelper->getQuestion('Do you confirm generation', 'yes', '?'), true);
if (!$questionHelper->ask($input, $output, $question)) {
$output->writeln('<error>Command aborted</error>');
return 1;
}
}
if (null === $input->getOption('controller')) {
throw new \RuntimeException('The controller option must be provided.');
}
list($bundle) = $this->parseShortcutNotation($input->getOption('controller'));
if (is_string($bundle)) {
$bundle = Validators::validateBundleName($bundle);
try {
$this->getContainer()->get('kernel')->getBundle($bundle);
} catch (\Exception $e) {
$output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</>', $bundle));
}
}
/** @var TemplateInterface $generator */
$generator = $this->getGenerator();
$questionHelper->writeSection($output, 'Controller generation');
$errors = array();
$runner = $questionHelper->getRunner($output, $errors);
$runner($generator->generate($input->getOption('controller')));
if (!$input->getOption('no-summary')) {
$questionHelper->writeGeneratorSummary($output, $generator->getErrors());
}
}
示例3: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$namespace = $input->getOption('namespace');
$bundleName = strtr($namespace, array('\\' => ''));
$bundleName = Validators::validateBundleName($bundleName);
$bundle = new Bundle($namespace, $bundleName, getcwd() . '/src', 'yml', true);
/**
* @var UnitedBundleGenerator $generator
*/
$generator = $this->getGenerator();
$output->writeln(sprintf('> Generating a united admin bundle skeleton into <info>%s</info> <comment>OK!</comment>', $this->makePathRelative($bundle->getTargetDirectory())));
// Write section
$questionHelper = $this->getQuestionHelper();
$questionHelper->writeSection($output, 'Bundle generation');
// generate the bundle
$generator->generateBundle($bundle);
// After generation we need to perform some app updates
$errors = array();
$runner = $questionHelper->getRunner($output, $errors);
// register the bundle in the Kernel class
$runner($this->updateKernel($output, $this->getContainer()->get('kernel'), $bundle));
// routing importing
$runner($this->updateRouting($output, $bundle));
// print summary
$questionHelper->writeGeneratorSummary($output, $errors);
}
示例4: 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);
}
示例5: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getQuestionHelper();
if ($input->isInteractive()) {
$question = new Question($questionHelper->getQuestion('Do you confirm generation', 'yes', '?'), true);
if (!$questionHelper->ask($input, $output, $question)) {
$output->writeln('<error>Command aborted</error>');
return 1;
}
}
if (null === $input->getOption('controller')) {
throw new \RuntimeException('The controller option must be provided.');
}
list($bundle, $controller) = $this->parseShortcutNotation($input->getOption('controller'));
if (is_string($bundle)) {
$bundle = Validators::validateBundleName($bundle);
try {
$bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
} catch (\Exception $e) {
$output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</>', $bundle));
}
}
$questionHelper->writeSection($output, 'Controller generation');
$generator = $this->getGenerator($bundle);
$generator->generate($bundle, $controller, $input->getOption('route-format'), $input->getOption('template-format'), $this->parseActions($input->getOption('actions')));
$output->writeln('Generating the bundle code: <info>OK</info>');
$questionHelper->writeGeneratorSummary($output, array());
}
示例6: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
// Start question helper
$questionHelper = $this->getQuestionHelper();
$questionHelper->writeSection($output, 'Welcome to the united CRUD generator!');
// get entity
$entity = $input->getOption('entity');
$question = new Question($questionHelper->getQuestion('Entity', $entity), $entity);
$question->setValidator(function ($answer) {
return Validators::validateEntityName($answer);
});
$complete = new EntitiesAutoCompleter($this->getContainer()->get('doctrine')->getManager());
$completeEntities = $complete->getSuggestions();
$question->setAutocompleterValues($completeEntities);
$entity = $questionHelper->ask($input, $output, $question);
$input->setOption('entity', $entity);
// get bundle
$destinationBundle = $input->getOption('bundle');
$question = new Question($questionHelper->getQuestion('Destination bundle', $destinationBundle), $destinationBundle);
$question->setValidator(function ($answer) {
return Validators::validateBundleName($answer);
});
$question->setAutocompleterValues($this->getBundleSuggestions());
$destinationBundle = $questionHelper->ask($input, $output, $question);
$input->setOption('bundle', $destinationBundle);
}
示例7: 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);
}
示例8: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getQuestionHelper();
if ($input->isInteractive() && !$input->getOption('no-summary')) {
$question = new Question($questionHelper->getQuestion('Do you confirm generation', 'yes', '?'), true);
if (!$questionHelper->ask($input, $output, $question)) {
$output->writeln('<error>Command aborted</error>');
return 1;
}
}
if (null === $input->getOption('entity')) {
throw new \RuntimeException('The entity option must be provided.');
}
list($bundle) = $this->parseShortcutNotation($input->getOption('entity'));
if (is_string($bundle)) {
$bundle = Validators::validateBundleName($bundle);
try {
$this->getContainer()->get('kernel')->getBundle($bundle);
} catch (\Exception $e) {
$output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</bg>', $bundle));
}
}
/** @var TemplateInterface $generator */
$generator = $this->getGenerator();
if ($input->getOption('no-backend')) {
$generator->setConfiguration('backend_crud', false);
}
if ($input->getOption('actions')) {
$generator->setConfiguration('actions', explode(',', $input->getOption('actions')));
}
$questionHelper->writeSection($output, 'CRUD generation');
$errors = array();
$runner = $questionHelper->getRunner($output, $errors);
if (!$input->getOption('no-backend')) {
$generator->setConfiguration('backend_bundle', $input->getOption('backend'));
}
$runner($generator->generate($input->getOption('entity'), $output));
if (!$input->getOption('no-backend')) {
$questionHelper->writeSection($output, "Don't forget to run sylius:rbac:initialize command");
}
if (!$input->getOption('no-summary')) {
$questionHelper->writeGeneratorSummary($output, $generator->getErrors());
}
}
示例9: 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);
}
示例10: 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);
}
示例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: 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);
}
示例13: 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);
}
示例14: 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;
}
示例15: validateBundle
/**
* Validate bundle
*
* @param $bundle
*
* @return AbstractResourceBundle
*/
private function validateBundle($bundle)
{
Validators::validateBundleName($bundle);
try {
$bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
} catch (\Exception $e) {
throw new \RuntimeException('Cannot patch "%s", bundle not found.', $bundle);
}
if (!$bundle instanceof AbstractResourceBundle) {
throw new \RuntimeException('You need to implement AbstractResourceBundle for "%s"', $bundle->getName());
}
return $bundle;
}