public static function execute_command($command, $pass_args = null) { if (!class_exists($command, false) && is_file(PTS_COMMAND_PATH . $command . '.php')) { include PTS_COMMAND_PATH . $command . '.php'; } if (is_file(PTS_COMMAND_PATH . $command . '.php') && method_exists($command, 'argument_checks')) { $argument_checks = call_user_func(array($command, 'argument_checks')); foreach ($argument_checks as &$argument_check) { $function_check = $argument_check->get_function_check(); $method_check = false; if (is_array($function_check) && count($function_check) == 2) { $method_check = $function_check[0]; $function_check = $function_check[1]; } if (substr($function_check, 0, 1) == '!') { $function_check = substr($function_check, 1); $return_fails_on = true; } else { $return_fails_on = false; } if ($method_check != false) { if (!method_exists($method_check, $function_check)) { echo PHP_EOL . 'Method check fails.' . PHP_EOL; continue; } $function_check = array($method_check, $function_check); } else { if (!function_exists($function_check)) { continue; } } if ($argument_check->get_argument_index() == 'VARIABLE_LENGTH') { $return_value = null; foreach ($pass_args as $arg) { $return_value = call_user_func_array($function_check, array($arg)); if ($return_value == true) { break; } } } else { $return_value = call_user_func_array($function_check, array(isset($pass_args[$argument_check->get_argument_index()]) ? $pass_args[$argument_check->get_argument_index()] : null)); } if ($return_value == $return_fails_on) { $command_alias = defined($command . '::doc_use_alias') ? constant($command . '::doc_use_alias') : $command; if (isset($pass_args[$argument_check->get_argument_index()]) && !empty($pass_args[$argument_check->get_argument_index()]) || $argument_check->get_argument_index() == 'VARIABLE_LENGTH' && !empty($pass_args)) { trigger_error('Invalid Argument: ' . implode(' ', $pass_args), E_USER_ERROR); } else { trigger_error('Phoronix Test Suite Argument Missing.', E_USER_ERROR); } echo PHP_EOL . 'CORRECT SYNTAX:' . PHP_EOL . 'phoronix-test-suite ' . str_replace('_', '-', $command_alias) . ' ' . implode(' ', $argument_checks) . PHP_EOL . PHP_EOL; if (method_exists($command, 'invalid_command')) { call_user_func_array(array($command, 'invalid_command'), $pass_args); echo PHP_EOL; } return false; } else { if ($argument_check->get_function_return_key() != null && !isset($pass_args[$argument_check->get_function_return_key()])) { $pass_args[$argument_check->get_function_return_key()] = $return_value; } } } } pts_module_manager::module_process('__pre_option_process', $command); if (is_file(PTS_COMMAND_PATH . $command . '.php')) { self::$current_command = $command; if (method_exists($command, 'run')) { call_user_func(array($command, 'run'), $pass_args); } else { echo PHP_EOL . 'There is an error in the requested command: ' . $command . PHP_EOL . PHP_EOL; } } else { if (($t = pts_module::valid_run_command($command)) != false) { list($module, $module_command) = $t; pts_module_manager::set_current_module($module); pts_module_manager::run_command($module, $module_command, $pass_args); pts_module_manager::set_current_module(null); } } echo PHP_EOL; pts_module_manager::module_process('__post_option_process', $command); }
public static function module_process($process, &$object_pass = null, $select_modules = false) { // Run a module process on all registered modules foreach (pts_module_manager::attached_modules($process, $select_modules) as $module) { pts_module_manager::set_current_module($module); $module_response = pts_module_manager::module_call($module, $process, $object_pass); switch ($module_response) { case pts_module::MODULE_UNLOAD: // Unload the PTS module pts_module_manager::detach_module($module); break; case pts_module::QUIT_PTS_CLIENT: // Stop the Phoronix Test Suite immediately pts_client::exit_client(); break; } } pts_module_manager::set_current_module(null); }