00001 <?php
00002
00003
00004
00005
00006
00007
00008 class Console {
00009
00010
00011
00012 public static function init() {
00013 if (!self::is_console_request()) {
00014 throw new Exception('Initialing console, but no console invoked');
00015 }
00016
00017 $argv = Arr::force($_SERVER['argv']);
00018 $action = Arr::get_item($argv, 1, '');
00019 parse_str(Arr::get_item($argv, 2, ''), $query);
00020 $method = strtoupper(Arr::get_item($argv, 3, 'GET'));
00021
00022 if (empty($action)) {
00023 $cmd = Arr::get_item($argv, 0, 'no command set');
00024 throw new Exception("Usage: $cmd route [arguments] [get|post]");
00025 }
00026
00027
00028 if ($method == 'POST') {
00029 $_POST = $query;
00030 $_GET = array();
00031 }
00032 else {
00033 $_POST = array();
00034 $_GET = $query;
00035 }
00036 $_GET[Config::get_value(Config::QUERY_PARAM_PATH_INVOKED)] = $action;
00037
00038
00039 Config::set_feature(Config::ENABLE_HTTPS, false);
00040
00041 return $action;
00042 }
00043
00044
00045
00046
00047
00048
00049 public static function is_console_request() {
00050 return RequestInfo::current()->is_console();
00051 }
00052
00053
00054
00055
00056
00057
00058
00059 public static function invoke($action) {
00060 $call = CONSOLE_PHP_INVOCATION . ' ' . APP_INCLUDE_ABSPATH . 'run_console.php ' . $action;
00061 Load::commands('generics/execute.shell');
00062 $cmd = new ExecuteShellCommand($call);
00063 return $cmd->execute();
00064 }
00065 }