Skip to content

Commit

Permalink
[FrameworkBundle] Adding lots of information for the user after init:…
Browse files Browse the repository at this point in the history
…bundle

This is mirrored off of the messages used by git flow and serves to give the user some initial direction (and to avoid "forgetting" the setup steps).

I realize that I've hardcoded documentation URLs into this task, but I think the benefit outweighs the cost of needing to make sure these are always up-to-date.
  • Loading branch information
weaverryan committed Mar 13, 2011
1 parent 843c449 commit 0f0539f
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php
Expand Up @@ -80,14 +80,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new \InvalidArgumentException('The bundle name must end with Bundle.');
}

// validate that the namespace is at least one level deep
if (false === strpos($namespace, '\\')) {
$msg = array();
$msg[] = sprintf('The namespace must contain a vendor namespace (e.g. "VendorName\%s" instead of simply "%s").', $namespace, $namespace);
$msg[] = 'If you\'ve specified a vendor namespace, did you forget to surround it with quotes (init:bundle "Acme\BlogBundle")?';

throw new \InvalidArgumentException(implode("\n\n", $msg));
}

$dir = $input->getArgument('dir');

// add trailing / if necessary
$dir = '/' === substr($dir, -1, 1) ? $dir : $dir.'/';

$targetDir = $dir.strtr($namespace, '\\', '/');

$output->writeln(sprintf('Initializing bundle "<info>%s</info>" in "<info>%s</info>"', $bundle, $dir));


if (file_exists($targetDir)) {
throw new \RuntimeException(sprintf('Bundle "%s" already exists.', $bundle));
Expand All @@ -103,5 +112,24 @@ protected function execute(InputInterface $input, OutputInterface $output)
));

rename($targetDir.'/Bundle.php', $targetDir.'/'.$bundle.'.php');

$output->writeln('<comment>Summary of actions</comment>');
$output->writeln(sprintf('- The bundle "<info>%s</info>" was created at "<info>%s</info>" and is using the namespace "<info>%s</info>".', $bundle, $targetDir, $namespace));
$output->writeln(sprintf('- The bundle contains a sample controller, a sample template and a sample routing file.'));

$output->writeln('');
$output->writeln('<comment>Follow-up actions</comment>');

$output->writeln('- Enable the bundle inside the AppKernel::registerBundles() method.');
$output->writeln(' Resource: <info>http://symfony.com/doc/2.0/book/page_creation.html#create-the-bundle</info>');

$output->writeln('- Ensure that the namespace is registered with the autoloader.');
$output->writeln(' Resource: <info>http://symfony.com/doc/2.0/book/page_creation.html#autoloading-introduction-sidebar</info>');

$output->writeln('- If using routing, import the bundle\'s routing resource.');
$output->writeln(' Resource: <info>http://symfony.com/doc/2.0/book/routing.html#including-external-routing-resources</info>');

$output->writeln('- Starting building your bundle!');
$output->writeln(' Resource: <info>http://symfony.com/doc/2.0/book/page_creation.html#the-hello-symfony-page</info>');
}
}

0 comments on commit 0f0539f

Please sign in to comment.