Sulu\Bundle\GeneratorBundle\Command\GenerateBundleCommand::execute PHP Method

execute() protected method

See also: Command
protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $dialog = $this->getDialogHelper();
        if ($input->isInteractive()) {
            if (!$dialog->askConfirmation($output, $dialog->getQuestion('Do you confirm generation', 'yes', '?'), true)) {
                $output->writeln('<error>Command aborted</error>');
                return 1;
            }
        }
        foreach (['namespace', 'dir'] as $option) {
            if (null === $input->getOption($option)) {
                throw new \RuntimeException(sprintf('The "%s" option must be provided.', $option));
            }
        }
        $namespace = Validators::validateBundleNamespace($input->getOption('namespace'));
        if (!($bundle = $input->getOption('bundle-name'))) {
            $bundle = strtr($namespace, ['\\' => '']);
        }
        $bundle = Validators::validateBundleName($bundle);
        $dir = Validators::validateTargetDir($input->getOption('dir'), $bundle, $namespace);
        $structure = $input->getOption('structure');
        $dialog->writeSection($output, 'Bundle generation');
        if (!$this->getContainer()->get('filesystem')->isAbsolutePath($dir)) {
            $dir = getcwd() . '/' . $dir;
        }
        $errors = [];
        $runner = $dialog->getRunner($output, $errors);
        // register the bundle in the Kernel class
        $runner($this->updateKernel($dialog, $input, $output, $this->getContainer()->get('kernel'), $namespace, $bundle));
        // routing
        $runner($this->updateRouting($dialog, $input, $output, $bundle));
        $generator = $this->getGenerator();
        $generator->generate($namespace, $bundle, $dir, $structure, $this->route);
        $output->writeln('Generating the bundle code: <info>OK</info>');
        // check that the namespace is already autoloaded
        $runner($this->checkAutoloader($output, $namespace, $bundle, $dir));
        $dialog->writeGeneratorSummary($output, $errors);
    }