public static function find_section_and_module($args, $section_arg_name, $section_question, $module_arg_name, $module_question) { $section_and_module = array(); if (isset($args[$section_arg_name])) { $section_and_module['section'] = $args[$section_arg_name]; } else { echo $section_question; $section_and_module['section'] = CLIScripts_InputReader::get_choice_from_string('haddock plug-ins project-specific'); if (!isset($section_and_module['section'])) { echo "Quitting!\n"; exit; } } $pdf = HaddockProjectOrganisation_ProjectDirectoryFinder::get_instance(); $project_directory = $pdf->get_project_directory_for_this_project(); if ($section_and_module['section'] != 'project-specific') { if (isset($args[$module_arg_name])) { $section_and_module['module'] = $args[$module_arg_name]; } else { if ($section_and_module['section'] == 'haddock') { $module_directories = $project_directory->get_core_module_directories(); } else { if ($section_and_module['section'] == 'plug-ins') { $module_directories = $project_directory->get_plug_in_module_directories(); } } $choice_str = ''; $first = TRUE; foreach ($module_directories as $md) { if ($first) { $first = FALSE; } else { $choice_str .= ' '; } $choice_str .= $md->get_identifying_name(); } echo $module_question; $section_and_module['module'] = CLIScripts_InputReader::get_choice_from_string($choice_str); if (!isset($section_and_module['module'])) { echo "Quitting!\n"; exit; } } } else { if (isset($args[$module_arg_name])) { throw new Exception('No module should be set if the section is project-specific!'); } } return $section_and_module; }
if ($script_section == 'plug-ins') { $module_directories = $project_directory->get_plug_in_module_directories(); } } $choice_str = ''; $first = TRUE; foreach ($module_directories as $md) { if ($first) { $first = FALSE; } else { $choice_str .= ' '; } $choice_str .= $md->get_identifying_name(); } echo "The module in which to save the script must be set: \n"; $script_module = CLIScripts_InputReader::get_choice_from_string($choice_str); if (!isset($script_module)) { echo "Quitting!\n"; exit; } } } else { if (isset($args['script-module'])) { throw new Exception('No module should be set in the section is project-specific!'); } } if (isset($args['script-name'])) { $script_name = $args['script-name']; } else { echo "Please enter a name for the script:\n"; $script_name = trim(fgets(STDIN));
} /* * Get the email address of the user. */ $email = ''; $got_valid_email = FALSE; if (isset($args['email'])) { $email = $args['email']; } $validator = new InputValidation_EmailAddressValidator(); if (strlen($email) > 0) { try { $validator->validate($email); $got_valid_email = TRUE; } catch (InputValidation_InvalidInputException $e) { echo $e->getMessage() . "\n"; $got_valid_email = FALSE; } } else { $got_valid_email = FALSE; } if (!$got_valid_email) { $email = CLIScripts_InputReader::get_validated_input("Please enter a valid email address: \n", $validator); } if (!$silent) { echo "The name: {$name}\n"; echo "The password: {$password}\n"; echo "The type: {$type}\n"; echo "Real name: {$real_name}\n"; echo "Email: {$email}\n"; }
*/ /* * Create the singleton objects. */ $pdf = HaddockProjectOrganisation_ProjectDirectoryFinder::get_instance(); $pd = $pdf->get_project_directory_for_this_project(); $plug_ins_dir = $pd->get_plug_in_modules_directory(); if (isset($args['plug-in'])) { $plug_in_name = $args['plug-in']; } else { echo "Which plug-in do you want to make abstract?\n"; $choice_str = ''; $first = TRUE; foreach ($plug_ins_dir->get_module_directories() as $m_d) { if ($first) { $first = FALSE; } else { $choice_str .= ' '; } $choice_str .= $m_d->get_identifying_name(); } $plug_in_name = CLIScripts_InputReader::get_choice_from_string($choice_str); if (!isset($plug_in_name)) { echo "Quitting!\n"; exit; } } $plug_in = $plug_ins_dir->get_module_directory($plug_in_name); if (!$silent) { printf("Plug-in module: %s\n", $plug_in->get_identifying_name()); }
<?php /** * The args for the list-cli-scripts script. * * @copyright Clear Line Web Design, 2007-08-03 */ echo "Do you want to list all the CLI scripts in the project?\n"; $all_project = CLIScripts_InputReader::ask_yes_no_question(); if (!$all_project) { $section_and_module = HaddockProjectOrganisation_CLIModuleDirectoryFinder::find_section_and_module($args, 'search-section', "Search for scripts in which section?\n", 'search-module', "Search for scripts in which module?\n"); } else { $section_and_module = NULL; } echo "Do you want to refresh the wrapper scripts?\n"; $refresh_wrapper_scripts = CLIScripts_InputReader::ask_yes_no_question(); if (!$silent) { if ($all_project) { echo "Searching the entire project.\n"; } else { echo "Searching individual modules.\n"; } if (isset($section_and_module)) { print_r($section_and_module); } echo ($refresh_wrapper_scripts ? 'R' : 'Not r') . "efreshing the wrapper scripts.\n"; }
// ) // ); //} } else { echo "Which plug-in do you want to make dependent on others?\n"; $choice_str = ''; $first = TRUE; foreach ($plug_ins_dir->get_module_directories() as $m_d) { if ($first) { $first = FALSE; } else { $choice_str .= ' '; } $choice_str .= $m_d->get_identifying_name(); } $dependent_name = CLIScripts_InputReader::get_choice_from_string($choice_str); if (!isset($dependent_name)) { echo "Quitting!\n"; exit; } } $dependent = $plug_ins_dir->get_module_directory($dependent_name); /* * ---------------------------------------- * Find out the modules that are going to be required. * ---------------------------------------- */ $available_modules = array(); foreach ($plug_ins_dir->get_module_directories() as $p_i_m_d) { if ($p_i_m_d->get_identifying_name() != $dependent->get_identifying_name()) { $available_modules[] = $p_i_m_d;
public function do_actions() { /* * Get the name, make sure that it is valid. */ if (isset($args['name'])) { $name = $args['name']; } else { echo "Please enter the name: \n"; $name = trim(fgets(STDIN)); } #echo "$name\n"; exit; $admin_login_manager = Admin_LoginManager::get_instance(); #print_r($admin_login_manager); exit; while (TRUE) { try { #echo "Reached the try block\n"; exit; if ($admin_login_manager->is_name_valid($name)) { #echo "The name is valid.\n"; exit; if ($admin_login_manager->is_name_available($name)) { #echo "The name is acceptable\n."; exit; if (!$silent) { echo "{$name} is an acceptable new name.\n"; } break; } else { echo "{$name} is not available.\n"; } } } catch (InputValidation_InvalidInputException $e) { echo $e->getMessage() . "\n"; } echo "Please try another name: \n"; $name = trim(fgets(STDIN)); } #echo "$name\n"; exit; /* * Get the password. */ if (isset($args['password'])) { $password = $args['password']; } else { echo "Please enter the password: \n"; $password = trim(fgets(STDIN)); } while (TRUE) { try { if ($admin_login_manager->is_password_valid($password)) { if (!$silent) { echo "{$password} is an acceptable new password.\n"; } break; } } catch (InputValidation_InvalidInputException $e) { echo $e->getMessage() . "\n"; } echo "Please try another password: \n"; $password = trim(fgets(STDIN)); } /* * Get the type of user. */ $type = ''; if (isset($args['type'])) { $type = $args['type']; } if (!$admin_login_manager->is_type_valid($type)) { if (strlen($type) > 0) { echo "Type not valid.\n"; } $types = $admin_login_manager->get_user_types(); $choice_str = join(' ', $types); $type = CLIScripts_InputReader::get_choice_from_string($choice_str); if ($type == NULL) { echo "Quitting!\n"; exit; } } /* * Get the real name of the user. */ $real_name = ''; if (isset($args['real-name'])) { $real_name = $args['real-name']; } else { echo "Please enter the real name of the user.\n"; $real_name = trim(fgets(STDIN)); } /* * Get the email address of the user. */ $email = ''; $got_valid_email = FALSE; if (isset($args['email'])) { $email = $args['email']; } $validator = new InputValidation_EmailAddressValidator(); if (strlen($email) > 0) { try { $validator->validate($email); $got_valid_email = TRUE; } catch (InputValidation_InvalidInputException $e) { echo $e->getMessage() . "\n"; $got_valid_email = FALSE; } } else { $got_valid_email = FALSE; } if (!$got_valid_email) { $email = CLIScripts_InputReader::get_validated_input("Please enter a valid email address: \n", $validator); } if (!$silent) { echo "The name: {$name}\n"; echo "The password: {$password}\n"; echo "The type: {$type}\n"; echo "Real name: {$real_name}\n"; echo "Email: {$email}\n"; } $admin_login_manager->add_new_user($name, $password, $type, $real_name, $email); if (!$silent) { echo "New user added.\n"; } }
// echo "No match!\n"; } } $class_name .= '_'; $stn_low = Formatting_ListOfWords::get_list_of_words_for_string($short_table_name, '_'); //echo 'print_r($stn_low): ' . "\n"; //print_r($stn_low); $class_name .= $stn_low->get_words_as_camel_case_string(); switch ($entity) { case 'table': $class_name .= 'Table'; break; } echo "Class name: {$class_name}\n"; echo "Is this class name acceptable?\n"; $class_name_acceptable = CLIScripts_InputReader::ask_yes_no_question(); if (!$class_name_acceptable) { echo "Please type the name of the class:\n"; $class_name = trim(fgets(STDIN)); } } if (isset($args['class-filename'])) { $class_filename = $args['class-filename']; } else { $class_filename = ''; if (!$module_directory->has_classes_directory()) { $module_directory->create_classes_directory(); } $classes_directory = $module_directory->get_classes_directory(); $class_filename = $classes_directory->get_filename_for_db_class($entity, $type, $class_name); }
echo "\n"; echo 'The following plug-in modules are required: '; echo "\n\n"; foreach ($required_plug_in_module_names as $r_p_i_m_n) { echo "\t{$r_p_i_m_n}\n"; } echo "\n"; if ($non_abstract_p_i_m_d->check_plug_in_module_dependencies()) { echo "All required plug-ins installed\n"; } else { $all_dependencies_met = FALSE; echo "The following plug-ins are missing:\n"; foreach ($non_abstract_p_i_m_d->get_missing_plug_in_module_names() as $m_p_i_m_n) { echo "{$m_p_i_m_n}\n"; } } } else { echo "No required plug-ins.\n"; } echo "\n"; } if ($all_dependencies_met) { printf("All plug-in modules in '%s' have all their dependencies met.\n", $plug_ins_dir->get_name()); } else { fwrite(STDERR, sprintf("Some plug-in modules in '%s' have missing required plug-in modules!\n", $plug_ins_dir->get_name())); } /* * Confirm exit from the user. */ CLIScripts_InputReader::confirm_continue('exit');
*/ if (isset($args['search-type'])) { $search_type = $args['search-type']; } else { echo "The type must be set:\n"; $choice_str = ''; $first = TRUE; foreach ($page_directory->get_types() as $type) { if ($first) { $first = FALSE; } else { $choice_str .= ' '; } $choice_str .= $type; } $search_type = CLIScripts_InputReader::get_choice_from_string($choice_str); } $page_manager = PublicHTML_PageManager::get_instance(); $page_manager->set_section($search_section); if ($search_section != 'project-specific') { $page_manager->set_module($search_module); } $page_manager->set_page($search_page); $page_manager->set_type($search_type); if (!$silent) { echo "The search section: {$search_section}\n"; if (isset($search_module)) { echo "The search module: {$search_module}\n"; } echo "The search page: {$search_page}\n"; echo "The search type: {$search_type}\n";
public function do_actions() { $batch_mode = isset($args['batch-mode']); $whole_project = isset($args['whole-project']); if (!$whole_project) { $section_and_module = HaddockProjectOrganisation_CLIModuleDirectoryFinder::find_section_and_module($args, 'search-section', "The section to search must be set:\n", 'search-module', "The module to search must be set:\n"); } if (isset($args['parent-class'])) { $parent_class = $args['parent-class']; } $output_in_csv = isset($args['csv']); //$output_in_csv = FALSE; //if ($batch_mode) { // $output_in_csv = isset($args['csv']); //} else { // if (isset($args['csv'])) { // $output_in_csv = TRUE; // } else { // echo "Output in CSVs?\n"; // $output_in_csv = CLIScripts_InputReader::get_choice_from_string('yes no'); // } //} $methods = FALSE; if ($batch_mode) { $methods = isset($args['methods']); } else { if (isset($args['methods'])) { $methods = TRUE; } else { echo "Search for methods?\n"; $methods = CLIScripts_InputReader::get_choice_from_string('yes no') == 'yes'; } } $files = FALSE; if ($batch_mode) { $files = isset($args['files']); } else { if (isset($args['files'])) { $files = TRUE; } else { echo "List the files?\n"; $files = CLIScripts_InputReader::get_choice_from_string('yes no') == 'yes'; } } if ($methods) { $sort_methods = FALSE; if (isset($args['sort-methods'])) { $sort_methods = TRUE; } else { echo "Sort the methods?\n"; $sort_methods = CLIScripts_InputReader::get_choice_from_string('yes no') == 'yes'; } } else { if (isset($args['sort-methods'])) { throw new Exception('--sort-methods must not be set if --methods is not set!'); } } if (!$silent) { echo $batch_mode ? "Running in batch mode.\n" : "Not running in batch mode.\n"; if ($whole_project) { echo "Searching the whole project.\n"; } else { echo 'Searching the ' . $section_and_module['section'] . " section.\n"; if ($section_and_module['section'] != 'project-specific') { echo 'Searching the ' . $section_and_module['module'] . " module.\n"; } } echo 'Output ' . ($output_in_csv ? '' : 'not ') . "in CSVs.\n"; echo ($methods ? 'L' : 'Not l') . "isting the methods.\n"; echo ($files ? 'L' : 'Not l') . "isting the files.\n"; } /* * Find the classes. */ $project_directory_finder = HaddockProjectOrganisation_ProjectDirectoryFinder::get_instance(); $project_directory = $project_directory_finder->get_project_directory_for_this_project(); $php_class_files = array(); if ($whole_project) { if (isset($parent_class)) { $php_class_files = $project_directory->get_php_subclass_files($parent_class); } else { $php_class_files = $project_directory->get_php_class_files(); } } else { if ($section_and_module['section'] == 'project-specific') { $module_directory = $project_directory->get_project_specific_directory(); } else { if ($section_and_module['section'] == 'haddock') { $module_directory = $project_directory->get_core_module_directory($section_and_module['module']); } elseif ($section_and_module['section'] == 'plug-ins') { $module_directory = $project_directory->get_plug_in_module_directory($section_and_module['module']); } } if ($parent_class) { $php_class_files = $module_directory->get_php_subclass_files($parent_class); } else { $php_class_files = $module_directory->get_php_class_files(); } } usort($php_class_files, array('FileSystem_PHPClassFile', 'cmp_php_class_names')); /* * Print off the data. */ if (count($php_class_files) > 0) { if ($methods) { /* * Does it makes sense to do this in batch mode or CSV mode? */ if (!$batch_mode and !$output_in_csv) { echo "Which class do you want to search for methods?\n"; $choice_str = ''; $first = TRUE; foreach ($php_class_files as $p_c_f) { if ($first) { $first = FALSE; } else { $choice_str .= ' '; } $choice_str .= $p_c_f->get_php_class_name(); } $class_name = CLIScripts_InputReader::get_choice_from_string($choice_str); $php_class_file = NULL; foreach ($php_class_files as $p_c_f) { if ($p_c_f->get_php_class_name() == $class_name) { $php_class_file = $p_c_f; break; } } if (isset($php_class_file)) { echo 'The methods of ' . $php_class_file->get_php_class_name(); if ($files) { echo ' saved in "PROJECT_ROOT . ' . $php_class_file->get_name_relative_to_dir(PROJECT_ROOT) . '"'; } echo ":\n\n"; $class_reflection_object = $php_class_file->get_reflection_class(); $method_names = array(); foreach ($class_reflection_object->getMethods() as $method) { if ($method->getDeclaringClass() == $class_reflection_object) { $method_names[] = $method->getName(); } } if ($sort_methods) { sort($method_names); } foreach ($method_names as $mn) { echo "\t{$mn}\n"; } echo "\n"; } } } else { if (!$output_in_csv) { echo "\nThe classes: \n\n"; } foreach ($php_class_files as $p_c_f) { if ($output_in_csv) { echo '"' . $p_c_f->get_php_class_name() . '"'; if ($files) { echo ','; echo '"' . $p_c_f->get_name_relative_to_dir(PROJECT_ROOT) . '"'; } echo "\n"; } else { echo "\t" . $p_c_f->get_php_class_name(); if ($files) { echo "\n"; echo "\t" . $p_c_f->get_name_relative_to_dir(PROJECT_ROOT) . "\n"; } echo "\n"; } } if (!$output_in_csv) { echo "\n"; } } } else { if (!$output_in_csv) { echo "No classes found!\n"; } } #/* # * Require a user response before exiting. # */ #if (!$batch_mode) { # echo "Press \"ENTER\" to exit.\n"; # $reply = trim(fgets(STDIN)); #} }
$files = isset($args['files']); } else { if (isset($args['files'])) { $files = TRUE; } else { echo "List the files?\n"; $files = CLIScripts_InputReader::get_choice_from_string('yes no') == 'yes'; } } if ($methods) { $sort_methods = FALSE; if (isset($args['sort-methods'])) { $sort_methods = TRUE; } else { echo "Sort the methods?\n"; $sort_methods = CLIScripts_InputReader::get_choice_from_string('yes no') == 'yes'; } } else { if (isset($args['sort-methods'])) { throw new Exception('--sort-methods must not be set if --methods is not set!'); } } if (!$silent) { echo $batch_mode ? "Running in batch mode.\n" : "Not running in batch mode.\n"; if ($whole_project) { echo "Searching the whole project.\n"; } else { echo 'Searching the ' . $section_and_module['section'] . " section.\n"; if ($section_and_module['section'] != 'project-specific') { echo 'Searching the ' . $section_and_module['module'] . " module.\n"; }