/** * Helper function to display errors in the console. * * @param $message * @param bool $exit */ private function writeError($message, $exit = false) { $this->output->writeln($this->dialog->getHelperSet()->get('formatter')->formatBlock($message, 'error')); if ($exit) { exit; } }
/** * @param DialogHelper $dialog The dialog 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(DialogHelper $dialog, InputInterface $input, OutputInterface $output, Bundle $bundle, $entityClass) { $auto = true; $multilang = false; if ($input->isInteractive()) { $multilang = $dialog->askConfirmation($output, $dialog->getQuestion('Is it a multilanguage site', 'yes', '?'), true); $auto = $dialog->askConfirmation($output, $dialog->getQuestion('Do you want to update the routing automatically', 'yes', '?'), true); } $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($dialog->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('/*******************************/'); }