public function __construct() { require_once 'Console/Getopt.php'; define('NO_ARGS', 1); define('INVALID_OPTION', 2); $args = Console_Getopt::readPHPArgv(); if (count($args) <= 1) { $this->usage(true); exit(1); } if (PEAR::isError($args)) { fputs(STDERR, $args->getMessage() . "\n"); exit(NO_ARGS); } if ($_SERVER['argv'][0] == $_SERVER['SCRIPT_NAME']) { $this->opts = Console_Getopt::getOpt($args, $this->short_opts, $this->long_opts); } else { $this->opts = Console_Getopt::getOpt2($args, $this->short_opts, $this->long_opts); } // Are the passed options valid? if (PEAR::isError($this->opts)) { fputs(STDERR, $this->opts->getMessage() . "\n"); exit(INVALID_OPTION); } $this->set_cache(); }
public function __construct() { $args = Console_Getopt::readPHPArgv(); if (PEAR::isError($args)) { fwrite(STDERR, $args->getMessage() . "\n"); exit(1); } // Compatibility between "php script.php" and "./script.php" if (realpath($_SERVER['argv'][0]) == __FILE__) { $this->options = Console_Getopt::getOpt($args, $this->short_format_config); } else { $this->options = Console_Getopt::getOpt2($args, $this->short_format_config); } // Check for invalid options if (PEAR::isError($this->options)) { fwrite(STDERR, $this->options->getMessage() . "\n"); $this->help(); } $this->command = array(); // Loop through the user provided options foreach ($this->options[0] as $option) { switch ($option[0]) { case 'h': help(); break; case 's': $this->command['syntax'] = $option[1]; break; case 't': $this->command['transform'] = $option[1]; break; case 'c': $this->command['config'] = $option[1]; break; } } // Loop through the user provided options foreach ($this->options[1] as $argument) { $this->command['query'] .= ' ' . $argument; } }