protected function updateRouting(QuestionHelper $questionHelper, InputInterface $input, OutputInterface $output, BundleInterface $bundle, $format, $entity, $prefix) { $auto = true; if ($input->isInteractive()) { $question = new ConfirmationQuestion($questionHelper->getQuestion('Confirm automatic update of the Routing', 'yes', '?'), true); $auto = $questionHelper->ask($input, $output, $question); } $output->write('Importing the CRUD routes: '); $this->getContainer()->get('filesystem')->mkdir($bundle->getPath() . '/Resources/config/'); // first, import the routing file from the bundle's main routing.yml file $routing = new RoutingManipulator($bundle->getPath() . '/Resources/config/routing.yml'); try { $ret = $auto ? $routing->addResource($bundle->getName(), $format, '/' . $prefix, 'routing/' . strtolower(str_replace('\\', '_', $entity))) : false; } catch (\RuntimeException $exc) { $ret = false; } if (!$ret) { $help = sprintf(" <comment>resource: \"@%s/Resources/config/routing/%s.%s\"</comment>\n", $bundle->getName(), strtolower(str_replace('\\', '_', $entity)), $format); $help .= sprintf(" <comment>prefix: /%s</comment>\n", $prefix); return array('- Import the bundle\'s routing resource in the bundle routing file', sprintf(' (%s).', $bundle->getPath() . '/Resources/config/routing.yml'), '', sprintf(' <comment>%s:</comment>', $routing->getImportedResourceYamlKey($bundle->getName(), $prefix)), $help, ''); } // second, import the bundle's routing.yml file from the application's routing.yml file $routing = new RoutingManipulator($this->getContainer()->getParameter('kernel.root_dir') . '/config/routing.yml'); try { $ret = $auto ? $routing->addResource($bundle->getName(), 'yml') : false; } catch (\RuntimeException $e) { // the bundle is already imported form app's routing.yml file $errorMessage = sprintf("\n\n[ERROR] The bundle's \"Resources/config/routing.yml\" file cannot be imported\n" . "from \"app/config/routing.yml\" because the \"%s\" bundle is\n" . "already imported. Make sure you are not using two different\n" . "configuration/routing formats in the same bundle because it won't work.\n", $bundle->getName()); $output->write($errorMessage); $ret = true; } catch (\Exception $e) { $ret = false; } if (!$ret) { return array('- Import the bundle\'s routing.yml file in the application routing.yml file', sprintf('# app/config/routing.yml'), sprintf('%s:', $bundle->getName()), sprintf(' <comment>resource: "@%s/Resources/config/routing.yml"</comment>', $bundle->getName()), '', '# ...', ''); } }