/** * @param QuestionHelper $questionHelper * @param InputInterface $input * @param OutputInterface $output * @param BundleInterface $bundle * @param $entity * @param $prefix * @return array */ 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 REST api routes: '); $this->getContainer()->get('filesystem')->mkdir($bundle->getPath() . '/Resources/config/'); $routing = new RoutingManipulator($this->getContainer()->getParameter('kernel.root_dir') . '/config/routing.yml'); try { $ret = $auto ? $routing->addResource($bundle->getName(), '/' . $prefix, $entity) : false; } catch (\RuntimeException $exc) { $ret = false; } if (!$ret) { $help = sprintf(" <comment>resource: \"@%s/Controller/%sRESTController.php\"</comment>\n", $bundle->getName(), $entity); $help .= sprintf(" <comment>type: %s</comment>\n", 'rest'); $help .= sprintf(" <comment>prefix: /%s</comment>\n", $prefix); return array('- Import this resource into the Apps routing file', sprintf(' (%s).', $this->getContainer()->getParameter('kernel.root_dir') . '/config/routing.yml'), '', sprintf(' <comment>%s:</comment>', substr($bundle->getName(), 0, -6) . '_' . $entity . ('' !== $prefix ? '_' . str_replace('/', '_', $prefix) : '')), $help, ''); } }
protected function updateRouting(DialogHelper $dialog, InputInterface $input, OutputInterface $output, BundleInterface $bundle, $entity, $prefix) { $auto = true; if ($input->isInteractive()) { $auto = $dialog->askConfirmation($output, $dialog->getQuestion('Confirm automatic update of the Routing', 'yes', '?'), true); } $output->write('Importing the REST api routes: '); $this->getContainer()->get('filesystem')->mkdir($bundle->getPath() . '/Resources/config/'); $routing = new RoutingManipulator($bundle->getPath() . '/Resources/config/routing.yml'); try { $auto ? $routing->addResource($bundle->getName(), $entity, '/' . $prefix) : false; } catch (\RuntimeException $exc) { $help = sprintf(" <comment>resource: \"@%s/Controller/%sRESTController.php\"</comment>\n", $bundle->getName(), strtolower(str_replace('\\', '_', ucfirst($entity)))); $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>', $bundle->getName() . ('' !== $prefix ? '_' . str_replace('/', '_', $prefix) : '')), $help, ''); } }