Adds a routing resource at the top of the existing ones.
protected function updateRouting(InputInterface $input, OutputInterface $output, $bundle, $format = "yml") { $refClass = new \ReflectionClass($bundle); $bundleRoutingFile = sprintf("%s/Resources/config/routing.%s", dirname($refClass->getFileName()), $format); if (is_file($bundleRoutingFile)) { $routing = new RoutingManipulator($this->getContainer()->getParameter('kernel.root_dir') . '/config/routing.yml'); $bundleName = substr($bundle, 1 + strrpos($bundle, "\\")); try { $ret = $routing->addResource($bundleName, $format); if (!$ret) { if ('annotation' === $format) { $help = sprintf(" <comment>resource: \"@%s/Controller/\"</comment>\n <comment>type: annotation</comment>\n", $bundle); } else { $help = sprintf(" <comment>resource: \"@%s/Resources/config/routing.%s\"</comment>\n", $bundle, $format); } $help .= " <comment>prefix: /</comment>\n"; $output->writeln("- Import the bundle\\'s routing resource in the app main routing file:\n"); $output->writeln(sprintf(" <comment>%s:</comment>\n", $bundle)); $output->writeln($help); } } catch (\RuntimeException $e) { $output->writeln(sprintf("Bundle <comment>%s</comment> is already imported.", $bundle)); throw $e; } } }
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/'); $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>', $bundle->getName() . ('' !== $prefix ? '_' . str_replace('/', '_', $prefix) : '')), $help, ''); } }
protected function updateRouting(QuestionHelper $questionHelper, InputInterface $input, OutputInterface $output, $bundle, $format) { $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 bundle routing resource: '); $routing = new RoutingManipulator($this->getContainer()->getParameter('kernel.root_dir') . '/config/routing.yml'); try { $ret = $auto ? $routing->addResource($bundle, $format) : true; if (!$ret) { if ('annotation' === $format) { $help = sprintf(" <comment>resource: \"@%s/Controller/\"</comment>\n <comment>type: annotation</comment>\n", $bundle); } else { $help = sprintf(" <comment>resource: \"@%s/Resources/config/routing.%s\"</comment>\n", $bundle, $format); } $help .= " <comment>prefix: /</comment>\n"; return array('- Import the bundle\'s routing resource in the app main routing file:', '', sprintf(' <comment>%s:</comment>', $bundle), $help, ''); } } catch (\RuntimeException $e) { return array(sprintf('Bundle <comment>%s</comment> is already imported.', $bundle), ''); } }
protected function updateRouting(OutputInterface $output, Bundle $bundle) { $targetRoutingPath = $this->getContainer()->getParameter('kernel.root_dir') . '/config/routing.yml'; $output->write(sprintf('> Importing the bundle\'s routes from the <info>%s</info> file: ', $this->makePathRelative($targetRoutingPath))); $routing = new RoutingManipulator($targetRoutingPath); try { $ret = $routing->addResource($bundle->getName(), $bundle->getConfigurationFormat()); if (!$ret) { if ('annotation' === $bundle->getConfigurationFormat()) { $help = sprintf(" <comment>resource: \"@%s/Controller/\"</comment>\n <comment>type: annotation</comment>\n", $bundle->getName()); } else { $help = sprintf(" <comment>resource: \"@%s/Resources/config/routing.%s\"</comment>\n", $bundle->getName(), $bundle->getConfigurationFormat()); } $help .= " <comment>prefix: /</comment>\n"; return array('- Import the bundle\'s routing resource in the app\'s main routing file:', '', sprintf(' <comment>%s:</comment>', $bundle->getName()), $help, ''); } } catch (\RuntimeException $e) { return array(sprintf('Bundle <comment>%s</comment> is already imported.', $bundle->getName()), ''); } }
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()), '', '# ...', ''); } }
private function updateRouting($dialog, InputInterface $input, OutputInterface $output, $namespace, $bundle, $format) { $auto = true; if ($input->isInteractive()) { $auto = $dialog->askConfirmation($output, $this->getQuestion('Confirm automatic update of the Routing', 'yes', '?'), true); } $output->write('Importing the bundle routing resource: '); $routing = new RoutingManipulator($this->container->getParameter('kernel.root_dir') . '/config/routing.yml'); $ret = $auto ? $routing->addResource($namespace, $bundle, $format) : false; if (!$ret) { if ('annotation' === $format) { $help = sprintf(" <comment>resource: \"@%s/Resources/Controller/\"</comment>\n <comment>type: annotation</comment>", $bundle); } else { $help = sprintf(" <comment>resource: \"@%s/Resources/config/routing.%s\"</comment>\n", $bundle, $format); } $help .= " <comment>prefix: /</comment>\n"; return array('- Import the bundle\'s routing resource in the app main routing file:', '', sprintf(' <comment>%s:</comment>', $bundle), $help, ''); } }