/** * Helper function to display errors in the console. * * @param $message * @param bool $exit */ private function writeError($message, $exit = false) { $this->output->writeln($this->questionHelper->getHelperSet()->get('formatter')->formatBlock($message, 'error')); if ($exit) { exit; } }
/** * @param QuestionHelper $questionHelper The question helper * @param InputInterface $input The command input * @param OutputInterface $output The command output * @param Bundle $bundle The bundle * @param string $entityClass The classname of the entity * * @return void */ protected function updateRouting(QuestionHelper $questionHelper, InputInterface $input, OutputInterface $output, Bundle $bundle, $entityClass) { $auto = true; $multilang = false; if ($input->isInteractive()) { $confirmationQuestion = new ConfirmationQuestion($questionHelper->getQuestion('Is it a multilanguage site', 'yes', '?'), true); $multilang = $questionHelper->ask($input, $output, $confirmationQuestion); $confirmationQuestion = new ConfirmationQuestion($questionHelper->getQuestion('Do you want to update the routing automatically', 'yes', '?'), true); $auto = $questionHelper->ask($input, $output, $confirmationQuestion); } $prefix = $multilang ? '/{_locale}' : ''; $code = sprintf("%s:\n", strtolower($bundle->getName()) . '_' . strtolower($entityClass) . '_admin_list'); $code .= sprintf(" resource: '@%s/Controller/%sAdminListController.php'\n", $bundle->getName(), $entityClass, "'"); $code .= " type: annotation\n"; $code .= sprintf(" prefix: %s/admin/%s/\n", $prefix, strtolower($entityClass)); if ($multilang) { $code .= " requirements:\n"; $code .= " _locale: %requiredlocales%\n"; } if ($auto) { $file = $bundle->getPath() . '/Resources/config/routing.yml'; $content = ''; if (file_exists($file)) { $content = file_get_contents($file); } elseif (!is_dir($dir = dirname($file))) { mkdir($dir, 0777, true); } $content .= "\n"; $content .= $code; if (false === file_put_contents($file, $content)) { $output->writeln($questionHelper->getHelperSet()->get('formatter')->formatBlock("Failed adding the content automatically", 'error')); } else { return; } } $output->writeln('Add the following to your routing.yml'); $output->writeln('/*******************************/'); $output->write($code); $output->writeln('/*******************************/'); }