/** * @param QuestionHelper $question * @param InputInterface $input * @param OutputInterface $output * @param BundleInterface $bundle * @param $metadata * @param $entity * @param $filename */ protected function generateAdmin(QuestionHelper $question, InputInterface $input, OutputInterface $output, BundleInterface $bundle, $metadata, $entity, $filename) { $auto = true; if ($input->isInteractive()) { $auto = $question->ask($input, $output, new ConfirmationQuestion('Confirm automatic generation of the Admin service?', false)); } if ($auto) { $group = ucfirst(str_replace('_', ' ', Container::underscore(substr($bundle->getName(), 0, -6)))); $label = $entity; $translationDomain = 'Sonata'; $groupQuestion = new Question('Group for the admin service: ', $group); $groupQuestion->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateEntityName')); $groupQuestion->setAutocompleterValues([$group]); $group = $question->ask($input, $output, $groupQuestion); $labelQuestion = new Question('Label for the admin service: ', $label); $labelQuestion->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateEntityName')); $labelQuestion->setAutocompleterValues([$label]); $label = $question->ask($input, $output, $labelQuestion); $translationDomainQuestion = new Question('Translation domain for the admin service: ', $translationDomain); $translationDomainQuestion->setAutocompleterValues([$translationDomain]); $translationDomain = $question->ask($input, $output, $labelQuestion); $output->write('Creating the service: '); $this->getContainer()->get('filesystem')->mkdir($bundle->getPath() . '/Resources/config/'); $admin = new AdminManipulator($bundle->getPath() . '/Resources/config/' . $filename); try { $ret = $auto ? $admin->addResource($bundle, $entity, $group, $label, $translationDomain) : false; } catch (\RuntimeException $exc) { $ret = false; } if ($ret) { $output->write('Creating the Admin class: '); $generator = $this->getGenerator($bundle); $generator->generateAdminClass($metadata[0], $input->getOption('overwrite')); } } }
/** * Initialize a configuration files */ public function initConfig(OutputInterface $output = null, $noInteraction = false) { $log = function ($message) use($output) { if ($output) { $output->writeln($message); } }; if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { throw new \RuntimeException('This feature is currently only supported on Linux and OSX (maybe). Please submit a PR to support it on windows.'); } $configDir = $this->getConfigDir(); $distDir = $this->getDistConfigDir(); if (!$this->filesystem->exists($configDir)) { $log('<info>[+] Creating directory:</info> ' . $configDir); $this->filesystem->mkdir($configDir); } $configFilenames = array('alias.yml', 'phpcrsh.yml'); foreach ($configFilenames as $configFilename) { $srcFile = $distDir . '/' . $configFilename; $destFile = $configDir . '/' . $configFilename; if (!$this->filesystem->exists($srcFile)) { throw new \Exception('Dist (source) file "' . $srcFile . '" does not exist.'); } if ($this->filesystem->exists($destFile)) { if (false === $noInteraction) { $confirmed = $this->questionHelper->askConfirmation($output, '"' . $configFilename . '" already exists, do you want to overwrite it?'); if (!$confirmed) { continue; } } else { $log(sprintf('<info>File</info> %s <info> already exists, not overwriting.', $destFile)); } } $this->filesystem->copy($srcFile, $destFile); $log('<info>[+] Creating file:</info> ' . $destFile); } }
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); } if (!$auto) { $output->write('Skipping importing the bundle routing resource: '); } else { $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), ''); } } }