/** * @param OutputInterface $output * @param HelperInterface $dialog * * @return mixed */ public function moduleQuestion(OutputInterface $output, HelperInterface $dialog) { $modules = $this->getSite()->getNoCoreModules(); return $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.common.questions.module'), ''), function ($module) { return $this->validateModuleExist($module); }, false, '', $modules); }
/** * Sets a helper. * * @param HelperInterface $helper The helper instance * @param string $alias An alias */ public function set(HelperInterface $helper, $alias = null) { $this->helpers[$helper->getName()] = $helper; if (null !== $alias) { $this->helpers[$alias] = $helper; } $helper->setHelperSet($this); }
/** * @param InputInterface $input * @param OutputInterface $output * @param HelperInterface $dialog * * @return mixed */ public function confirmationQuestion(InputInterface $input, OutputInterface $output, HelperInterface $dialog) { if ($input->isInteractive()) { if (!$dialog->askConfirmation($output, $dialog->getQuestion($this->trans('commands.common.questions.confirm'), 'yes', '?'), true)) { $output->writeln('<error>' . $this->trans('commands.common.messages.canceled') . '</error>'); return true; } return false; } return false; }
/** * Mocks question helper. */ protected function mockQuestionHelper(array $answers) { foreach ($answers as $key => $answer) { $this->questionHelper->expects($this->at($key + 2))->method('ask')->will($this->returnValue($answer)); } $this->helperSet->set($this->questionHelper, 'question'); }
/** * @param OutputInterface $output * @param HelperInterface $dialog * * @return mixed */ public function eventsQuestion(OutputInterface $output, HelperInterface $dialog) { $eventCollection = []; $output->writeln($this->trans('commands.common.questions.events.message')); $events = $this->getEvents(); while (true) { $event = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.common.questions.events.name'), ''), function ($event) use($events) { return $this->validateServiceExist($event, $events); }, false, null, $events); if (empty($event)) { break; } $callbackSuggestion = str_replace('.', '_', $event); $callback = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.event.subscriber.questions.callback-name'), $callbackSuggestion), $callbackSuggestion); $eventCollection[$event] = $callback; $eventKey = array_search($event, $events, true); if ($eventKey >= 0) { unset($events[$eventKey]); } } return $eventCollection; }
/** * @param OutputInterface $output * @param HelperInterface $dialog * @return mixed */ public function servicesQuestion(OutputInterface $output, HelperInterface $dialog) { if ($dialog->askConfirmation($output, $dialog->getQuestion($this->trans('commands.common.questions.services.confirm'), 'no', '?'), false)) { $service_collection = []; $output->writeln($this->trans('commands.common.questions.services.message')); $services = $this->getServices(); while (true) { $service = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.common.questions.services.name'), ''), function ($service) use($services) { return $this->validateServiceExist($service, $services); }, false, null, $services); if (empty($service)) { break; } array_push($service_collection, $service); $service_key = array_search($service, $services, true); if ($service_key >= 0) { unset($services[$service_key]); } } return $service_collection; } return null; }
/** * @param OutputInterface $output * @param HelperInterface $dialog * * @return mixed */ public function regionQuestion(OutputInterface $output, HelperInterface $dialog) { $stringUtils = $this->getStringUtils(); $validators = $this->getValidator(); $regions = []; while (true) { $region_name = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.theme.questions.region-name'), 'Content'), 'Content'); $region_machine_name = $stringUtils->createMachineName($region_name); $region_machine_name = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.theme.questions.region-machine-name'), $region_machine_name), function ($region_machine_name) use($validators) { return $validators->validateMachineName($region_machine_name); }, false, $region_machine_name, null); array_push($regions, array('region_name' => $region_name, 'region_machine_name' => $region_machine_name)); if (!$dialog->askConfirmation($output, $dialog->getQuestion($this->trans('commands.generate.theme.questions.region-add'), 'yes', '?'), true)) { break; } } return $regions; }
/** * Execute the command. * * @param InputInterface $input * @param OutputInterface $output * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $this->input = $input; $this->output = $output; $this->helper = $this->getHelper('question'); // Get the server name $question = new Question("Please enter the server name, this will be used in the virtual host and in the entry inside the hosts file\r\n", 'Test'); $serverName = $this->helper->ask($input, $output, $question); $this->info(""); $this->info(""); $question = new Question("Please enter the directory name, the folder will be created here:\r\n<info>C:\\xampp\\htdocs\\[directory name]</info>\r\n", 'Test'); $directoryName = $this->helper->ask($input, $output, $question); $this->info(""); $this->info(""); $question = new Question("Please enter a comment to identify this virtual host (optional, press enter to ignore)\r\n", $directoryName . " - " . $serverName); $comment = $this->helper->ask($input, $output, $question); $this->info("Building Virtual Host..."); $this->setVirtualHostFile(); $this->createVirtualHost($serverName, $directoryName, $comment); print_r($this->vhost); $this->saveVirtualHost(); $this->info("Successfully added Virtual Host"); $this->info(""); $this->info(""); $this->info("Proceeding to add the entry to the hosts file"); $question = new ConfirmationQuestion('Change the default 127.0.0.1 local address? (y=yes, n=no)', false); $ip = "127.0.0.1"; if ($this->helper->ask($input, $output, $question)) { $question = new Question("Please enter a new IP:\r\n", '127.0.0.1'); $ip = $this->helper->ask($input, $output, $question); } $this->createNewHost($serverName, $ip); $this->info(""); print_r($this->host); $this->setHostsFile(); $this->saveHost(); $this->info("\r\n\r\nSuccessfully saved the virtual host and the hosts file"); // @TODO Check whether host already exists //$this->verifyVirtualHostDoesntExist( $input->getArgument('name') ); }
/** * @param OutputInterface $output * @param HelperInterface $dialog * * @return mixed */ public function dbPortQuestion(OutputInterface $output, HelperInterface $dialog) { return $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.migrate.execute.questions.db-port'), '3306'), function ($value) { if (!strlen(trim($value))) { throw new \Exception('The option can not be empty'); } return $value; }, false, '3306'); }
/** * @param OutputInterface $output * @param HelperInterface $dialog * * @return mixed */ public function permissionQuestion(OutputInterface $output, HelperInterface $dialog) { $permissions = []; $boolOrNone = ['true', 'false', 'none']; while (true) { $permission = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.permission.questions.permission'), 'access content'), 'access content'); $title = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.permission.questions.title'), 'Access content'), 'Access content'); $description = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.permission.questions.description'), 'Allow access to my content'), 'Allow access to my content'); $restrictAccess = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.permission.questions.restrict-access'), 'none', '?'), function ($answer) use($boolOrNone) { if (!in_array($answer, $boolOrNone)) { throw new \RuntimeException('The values can be true, false or none'); } return $answer; }, false, 'none', $boolOrNone); $permission = $this->getStringUtils()->camelCaseToLowerCase($permission); $title = $this->getStringUtils()->anyCaseToUcFirst($title); array_push($permissions, array('permission' => $permission, 'title' => $title, 'description' => $description, 'restrict_access' => $restrictAccess)); if (!$dialog->askConfirmation($output, $dialog->getQuestion($this->trans('commands.generate.permission.questions.add'), 'yes', '?'), true)) { break; } } return $permissions; }
/** * @param OutputInterface $output * @param HelperInterface $dialog * * @return mixed */ public function formQuestion(OutputInterface $output, HelperInterface $dialog) { if ($dialog->askConfirmation($output, $dialog->getQuestion($this->trans('commands.common.questions.inputs.confirm'), 'yes', '?'), true)) { $input_types = ['color', 'checkbox', 'checkboxes', 'date', 'datetime', 'email', 'number', 'password', 'password_confirm', 'range', 'radios', 'select', 'tel', 'textarea', 'textfield']; $inputs = []; while (true) { // Label for input $input_label = $dialog->ask($output, $dialog->getQuestion(' ' . $this->trans('commands.common.questions.inputs.label'), '', ':'), null); if (empty($input_label)) { break; } // Machine name $input_machine_name = $this->getStringUtils()->createMachineName($input_label); $input_name = $dialog->ask($output, $dialog->getQuestion(' ' . $this->trans('commands.common.questions.inputs.machine_name'), $input_machine_name, ':'), $input_machine_name); // Type input $input_type = $dialog->askAndValidate($output, $dialog->getQuestion(' ' . $this->trans('commands.common.questions.inputs.type'), 'textfield', ':'), function ($input) use($input_types) { if (!in_array($input, $input_types)) { throw new \InvalidArgumentException(sprintf($this->trans('commands.common.questions.inputs.invalid'), $input)); } return $input; }, false, 'textfield', $input_types); $maxlength = null; $size = null; if (in_array($input_type, array('textfield', 'password', 'password_confirm'))) { $maxlength = $dialog->ask($output, $dialog->getQuestion(' Maximum amount of character', '', ':'), null); $size = $dialog->ask($output, $dialog->getQuestion(' Width of the textfield (in characters)', '', ':'), null); } if ($input_type == 'select') { $size = $dialog->ask($output, $dialog->getQuestion(' Size of multiselect box (in lines)', '', ':'), null); } $input_options = ''; if (in_array($input_type, array('checkboxes', 'radios', 'select'))) { $input_options = $dialog->ask($output, $dialog->getQuestion(' Input options separated by comma', '', ':'), null); } // Prepare options as an array if (strlen(trim($input_options))) { // remove spaces in options and empty options $input_options = array_filter(array_map('trim', explode(',', $input_options))); // Create array format for options foreach ($input_options as $key => $value) { $input_options_output[$key] = "\$this->t('" . $value . "') => \$this->t('" . $value . "')"; } $input_options = 'array(' . implode(', ', $input_options_output) . ')'; } // Description for input $input_description = $dialog->ask($output, $dialog->getQuestion(' ' . $this->trans('commands.common.questions.inputs.description'), '', ':'), null); // Default value for input $default_value = $dialog->ask($output, $dialog->getQuestion(' ' . $this->trans('commands.common.questions.inputs.default-value'), '', ':'), null); // Weight for input $weight = $dialog->ask($output, $dialog->getQuestion(' ' . $this->trans('commands.common.questions.inputs.weight'), '', ':'), null); array_push($inputs, array('name' => $input_name, 'type' => $input_type, 'label' => $input_label, 'options' => $input_options, 'description' => $input_description, 'maxlength' => $maxlength, 'size' => $size, 'default_value' => $default_value, 'weight' => $weight)); } return $inputs; } return; }
/** * @param OutputInterface $output * @param HelperInterface $dialog * * @return mixed */ public function breakpointQuestion(OutputInterface $output, HelperInterface $dialog) { $stringUtils = $this->getHelperSet()->get('stringUtils'); $validators = $this->getHelperSet()->get('validators'); $breakpoints = []; while (true) { $breakpoint_name = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.theme.questions.breakpoint-name'), 'narrow'), function ($breakpoint_name) use($validators) { return $validators->validateMachineName($breakpoint_name); }, false, 'narrow', null); $breakpoint_label = $stringUtils->createMachineName($breakpoint_name); $breakpoint_label = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.theme.questions.breakpoint-label'), $breakpoint_label), function ($breakpoint_label) use($validators) { return $validators->validateMachineName($breakpoint_label); }, false, $breakpoint_label, null); $breakpoint_media_query = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.theme.questions.breakpoint-media-query'), 'all and (min-width: 560px) and (max-width: 850px)'), 'all and (min-width: 560px) and (max-width: 850px)'); $breakpoint_weight = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.theme.questions.breakpoint-weight'), '1'), '1'); $breakpoint_multipliers = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.theme.questions.breakpoint-multipliers'), '1x'), '1x'); array_push($breakpoints, array('breakpoint_name' => $breakpoint_name, 'breakpoint_label' => $breakpoint_label, 'breakpoint_media_query' => $breakpoint_media_query, 'breakpoint_weight' => $breakpoint_weight, 'breakpoint_multipliers' => $breakpoint_multipliers)); if (!$dialog->askConfirmation($output, $dialog->getQuestion($this->trans('commands.generate.theme.questions.breakpoint-add'), 'yes', '?'), true)) { break; } } return $breakpoints; }