예제 #1
0
 /**
  * @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;
 }
예제 #2
0
 /**
  * @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;
 }
 /**
  * @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;
 }
예제 #4
0
 /**
  * @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 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;
 }
예제 #6
0
 /**
  * @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;
 }