*/
trait BundleTrait
{
/**
* @return ContainerInterface
*/
protected abstract function getContainer();
/**
* Returns the selected bundle.
* If no bundle argument is set, the user will get ask for it.
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return BundleInterface
*/
protected function getBundle(InputInterface $input, OutputInterface $output)
{
$kernel = $this
->getContainer()
->get('kernel');
if ($input->hasArgument('bundle') && '@' === substr($input->getArgument('bundle'), 0, 1)) {
return $kernel->getBundle(substr($input->getArgument('bundle'), 1));
}
$bundleNames = array_keys($kernel->getBundles());
do {
$question = 'Select the bundle: ';
$question = new Question($question);
$question->setAutocompleterValues($bundleNames);
$bundleName = $this->getHelperSet()->get('question')->ask($input, $output, $question);
if (in_array($bundleName, $bundleNames)) {
break;
}
$output->writeln(sprintf('Bundle "%s" does not exist.', $bundleName));
} while (true);
return $kernel->getBundle($bundleName);
}
}