public function addActions(InputInterface $input, OutputInterface $output, \Sensio\Bundle\GeneratorBundle\Command\Helper\QuestionHelper $questionHelper) { $output->writeln(array('', 'Instead of starting with a blank controller, you can add some actions now. An action', 'is a PHP function or method that executes, for example, when a given route is matched.', 'Actions should be suffixed by <comment>Action</comment>.', '')); $templateNameValidator = function ($name) { if ('default' == $name) { return $name; } if (2 != substr_count($name, ':')) { throw new \InvalidArgumentException(sprintf('Template name "%s" does not have 2 colons', $name)); } return $name; }; $actions = $this->parseActions($input->getOption('actions')); while (true) { // name $output->writeln(''); $actionName = $questionHelper->askAndValidate($output, $questionHelper->getQuestion('New action name (press <return> to stop adding actions)', null), function ($name) use($actions) { if (null == $name) { return $name; } if (isset($actions[$name])) { throw new \InvalidArgumentException(sprintf('Action "%s" is already defined', $name)); } return $name; }); if (!$actionName) { break; } $usualActions = array('home', 'add', 'see', 'modify', 'delete'); if (in_array($actionName, $usualActions)) { $route = '/' . $actionName; $placeholders = $this->getPlaceholdersFromRoute($route); $template = $input->getOption('controller') . ':' . $actionName . '.html.' . $input->getOption('template-format'); } else { // route $route = $questionHelper->ask($output, $questionHelper->getQuestion('Action route', '/' . $actionName), '/' . $actionName); $placeholders = $this->getPlaceholdersFromRoute($route); // template $defaultTemplate = $input->getOption('controller') . ':' . $actionName . '.html.' . $input->getOption('template-format'); $template = $questionHelper->askAndValidate($output, $questionHelper->getQuestion('Templatename (optional)', $defaultTemplate), $templateNameValidator, false, 'default'); } // adding action $actions[$actionName] = array('name' => $actionName, 'route' => $route, 'placeholders' => $placeholders, 'template' => $template); } return $actions; }