コード例 #1
0
ファイル: CLI.php プロジェクト: leloulight/Sprint
     * I tried to use getopt but had it fail occasionally to find any
     * but argc has always had our back. We don't have all of the "power"
     * of getopt but this does us just fine.
     */
    protected static function parseCommand()
    {
        $options_found = false;
        for ($i = 1; $i < $_SERVER['argc']; $i++) {
            // If there's no '-' at the beginning of the argument
            // then add it to our segments.
            if (!$options_found && strpos($_SERVER['argv'][$i], '-') === false) {
                self::$segments[] = $_SERVER['argv'][$i];
                continue;
            }
            $options_found = true;
            if (substr($_SERVER['argv'][$i], 0, 1) != '-') {
                continue;
            }
            $arg = str_replace('-', '', $_SERVER['argv'][$i]);
            $value = null;
            // If the next item starts with a dash it's a value
            if (isset($_SERVER['argv'][$i + 1]) && substr($_SERVER['argv'][$i + 1], 0, 1) != '-') {
                $value = $_SERVER['argv'][$i + 1];
                $i++;
            }
            self::$options[$arg] = $value;
        }
    }
}
CLI::_init();