public static function get_choice_from_string_array($choices) { #while (TRUE) { # echo "Please choose: \n"; # # for ($i = 0; $i < count($choices); $i++) { # echo "$i) " . $choices[$i] . "\n"; # } # # echo "Type \"b\" to go back.\n"; # # $choice = trim(fgets(STDIN)); # # if (preg_match('/b/i', $choice)) { # return NULL; # } # # if (preg_match('/^\d+$/', $choice)) { # if (($choice >= 0) and ($choice < count($choices))) { # return $choices[$choice]; # } else { # echo "Out of range!\n"; # } # } else { # echo "Please enter a number!\n"; # } #} return CLIScripts_UserInterrogationHelper::get_choice_from_string_array($choices); }
public function do_actions() { if ($this->has_arg('datum-name')) { $datum_name = $this->get_arg('datum-name'); } else { echo 'Which datum do you want to set?' . PHP_EOL; $datum_name = CLIScripts_UserInterrogationHelper::get_choice_from_string_array(array('Name', 'Title', 'Copyright Holder', 'Version Code', 'Camel Case Root')); echo "Setting the '{$datum_name}'" . PHP_EOL; } if ($this->has_arg('new-value')) { $new_value = $this->get_arg('new-value'); } else { echo 'Please enter the new value:' . PHP_EOL; $new_value = trim(fgets(STDIN)); echo 'New value: ' . $new_value . PHP_EOL; } switch ($datum_name) { case 'Name': HaddockProjectOrganisation_ProjectInformationHelper::set_name($new_value); break; case 'Title': HaddockProjectOrganisation_ProjectInformationHelper::set_title($new_value); break; case 'Copyright Holder': HaddockProjectOrganisation_ProjectInformationHelper::set_copyright_holder($new_value); break; case 'Version Code': HaddockProjectOrganisation_ProjectInformationHelper::set_version_code($new_value); break; case 'Camel Case Root': HaddockProjectOrganisation_ProjectInformationHelper::set_camel_case_root($new_value); break; } }
private function get_remote_server() { if ($this->has_arg('remote-server')) { return $this->get_arg('remote-server'); } else { $remote_servers = ServerAdminScripts_MySQLDumpsDownloadingHelper::get_remote_servers(); if (count($remote_servers) > 0) { echo 'Please choose the server address to delete:' . PHP_EOL; return CLIScripts_UserInterrogationHelper::get_choice_from_string_array($remote_servers); } } }
public static function get_module_directory_from_cli_choice() { $module_directories = self::get_all_module_directories(); usort($module_directories, create_function('$a, $b', 'return strcmp($a->get_identifying_name(), $b->get_identifying_name());')); $mds = array(); $first = TRUE; foreach ($module_directories as $module_directory) { $name = $module_directory->get_identifying_name(); $mds[$name] = $module_directory; } $chosen_module_name = CLIScripts_UserInterrogationHelper::get_choice_from_string_array(array_keys($mds)); return $mds[$chosen_module_name]; }
public static function get_user_entry_from_cli_choice() { /* * Get the array of users. */ $all_user_entries = Admin_UsersHelper::get_all_user_entries(); /* * Do a bit of array manipulation to put users * into a hash with the names as the key. */ $users_hash = array(); foreach ($all_user_entries as $user_entry) { $users_hash[$user_entry->get_name()] = $user_entry; } /* * Get the user's choice of user. */ return $users_hash[CLIScripts_UserInterrogationHelper::get_choice_from_string_array(array_keys($users_hash))]; }