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; } } }
public function testHasResourceInAnnotationReturnFalseIfOnlyOneControllerDefined() { $tmpDir = sys_get_temp_dir() . '/sf2'; $file = tempnam($tmpDir, 'routing'); $routing = <<<DATA acme_demo_post: resource: "@AcmeDemoBundle/Controller/PostController.php" type: annotation DATA; file_put_contents($file, $routing); $manipulator = new RoutingManipulator($file); $this->assertFalse($manipulator->hasResourceInAnnotation('AcmeDemoBundle')); }
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 updateAnnotationRouting(BundleInterface $bundle, $entity, $prefix) { $rootDir = $this->getContainer()->getParameter('kernel.root_dir'); $routing = new RoutingManipulator($rootDir . '/config/routing.yml'); if (!$routing->hasResourceInAnnotation($bundle->getName())) { $parts = explode('\\', $entity); $controller = array_pop($parts); $ret = $routing->addAnnotationController($bundle->getName(), $controller); } }
/** * @dataProvider getImportedResourceYamlKeys */ public function testGetImportedResourceYamlKey($bundleName, $prefix, $expectedKey) { $manipulator = new RoutingManipulator(__FILE__); $key = $manipulator->getImportedResourceYamlKey($bundleName, $prefix); $this->assertEquals($expectedKey, $key); }
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, ''); } }
/** * Constructor. * * @param string $file The YAML routing file path */ public function __construct($file) { $this->file = $file; parent::__construct($file); }